Skip to content

Commit

Permalink
Merge pull request #1139 from dpc-sdp/bugfix/R20-1868-clr-btn-fix
Browse files Browse the repository at this point in the history
fix(@dpc-sdp/ripple-ui-core): fixed search bar clear btn submitting form when not wanted
  • Loading branch information
jeffdowdle authored Apr 30, 2024
2 parents d0196b9 + ab209fd commit 91d239a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
Expand Down
32 changes: 18 additions & 14 deletions packages/ripple-ui-core/src/components/search-bar/RplSearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface Props {
isOptionSelectable?: Function
showLabel?: boolean
isFreeText?: boolean
submitOnClear?: boolean
}
const props = withDefaults(defineProps<Props>(), {
Expand All @@ -49,7 +50,8 @@ const props = withDefaults(defineProps<Props>(), {
getOptionId: (opt) => opt,
isOptionSelectable: (opt) => true,
showLabel: false,
isFreeText: true
isFreeText: true,
submitOnClear: false
})
type Timer = ReturnType<typeof setTimeout>
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 91d239a

Please sign in to comment.