Skip to content

Commit

Permalink
fix(VField): stopPropagation mousedown event on clearable icon (#16945)
Browse files Browse the repository at this point in the history
Co-authored-by: John Leider <john@vuetifyjs.com>
  • Loading branch information
yuwu9145 and johnleider authored Mar 27, 2023
1 parent f4f5d7b commit 7e7a467
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/vuetify/src/components/VCombobox/VCombobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export const VCombobox = genericComponent<new <
},
})
const selectionIndex = ref(-1)
let cleared = false
const color = computed(() => vTextFieldRef.value?.color)
const { items, transformIn, transformOut } = useItems(props)
const { textColorClasses, textColorStyles } = useTextColor(color)
Expand Down Expand Up @@ -156,12 +157,19 @@ export const VCombobox = genericComponent<new <
}

if (!val) selectionIndex.value = -1
if (isFocused.value) menu.value = true

isPristine.value = !val
},
})
watch(_search, value => {
if (cleared) {
// wait for clear to finish, VTextField sets _search to null
// then search computed triggers and updates _search to ''
nextTick(() => (cleared = false))
} else if (isFocused.value && !menu.value) {
menu.value = true
}

emit('update:search', value)
})
watch(model, value => {
Expand Down Expand Up @@ -190,6 +198,8 @@ export const VCombobox = genericComponent<new <
const listRef = ref<VList>()

function onClear (e: MouseEvent) {
cleared = true

if (props.openOnClear) {
menu.value = true
}
Expand Down
4 changes: 4 additions & 0 deletions packages/vuetify/src/components/VField/VField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ export const VField = genericComponent<new <T>() => {
<div
class="v-field__clearable"
v-show={ props.dirty }
onMousedown={ (e: MouseEvent) => {
e.preventDefault()
e.stopPropagation()
}}
>
{ slots.clear
? slots.clear()
Expand Down

0 comments on commit 7e7a467

Please sign in to comment.