From ab209fd09714ca235e4948dad478eeefd096d3fe Mon Sep 17 00:00:00 2001 From: Jeffrey Dowdle Date: Tue, 30 Apr 2024 11:33:50 +1000 Subject: [PATCH] fix(@dpc-sdp/ripple-ui-core): fixed search bar clear btn submitting form when not wanted --- .../global/TideSearchAddressLookup.vue | 1 + .../components/search-bar/RplSearchBar.vue | 32 +++++++++++-------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/packages/ripple-tide-search/components/global/TideSearchAddressLookup.vue b/packages/ripple-tide-search/components/global/TideSearchAddressLookup.vue index 41f10468c1..77f7992222 100644 --- a/packages/ripple-tide-search/components/global/TideSearchAddressLookup.vue +++ b/packages/ripple-tide-search/components/global/TideSearchAddressLookup.vue @@ -15,6 +15,7 @@ :getOptionId="(itm:any) => itm?.id || itm?.name" :getSuggestionVal="(itm:any) => itm?.name || ''" :isFreeText="false" + :submitOnClear="true" @submit="submitAction" @update:input-value="onUpdate" > diff --git a/packages/ripple-ui-core/src/components/search-bar/RplSearchBar.vue b/packages/ripple-ui-core/src/components/search-bar/RplSearchBar.vue index 914fb2f04f..60933f8c00 100644 --- a/packages/ripple-ui-core/src/components/search-bar/RplSearchBar.vue +++ b/packages/ripple-ui-core/src/components/search-bar/RplSearchBar.vue @@ -31,6 +31,7 @@ interface Props { isOptionSelectable?: Function showLabel?: boolean isFreeText?: boolean + submitOnClear?: boolean } const props = withDefaults(defineProps(), { @@ -49,7 +50,8 @@ const props = withDefaults(defineProps(), { getOptionId: (opt) => opt, isOptionSelectable: (opt) => true, showLabel: false, - isFreeText: true + isFreeText: true, + submitOnClear: false }) type Timer = ReturnType @@ -173,19 +175,21 @@ const handleClear = async () => { emit('update:inputValue', null) internalValue.value = '' - emitRplEvent( - 'submit', - { - action: 'search', - id: props.id, - text: '', - name: props.inputLabel, - value: '', - payload: null, - type: 'suggestion' - }, - { global: props.globalEvents } - ) + if (props.submitOnClear) { + emitRplEvent( + 'submit', + { + action: 'search', + id: props.id, + text: '', + name: props.inputLabel, + value: '', + payload: null, + type: 'suggestion' + }, + { global: props.globalEvents } + ) + } await nextTick() inputRef.value?.focus()