Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(VField): stopPropagation mousedown event on clearable icon #16945

Merged
merged 6 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 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)
const cleared = ref(false)
johnleider marked this conversation as resolved.
Show resolved Hide resolved
const color = computed(() => vTextFieldRef.value?.color)
const { items, transformIn, transformOut } = useItems(props)
const { textColorClasses, textColorStyles } = useTextColor(color)
Expand Down Expand Up @@ -156,12 +157,20 @@ export const VCombobox = genericComponent<new <
}

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

isPristine.value = !val
},
})
watch(_search, value => {
if (cleared.value) {
// Implement open-on-clear (https://github.com/vuetifyjs/vuetify/issues/16925)
johnleider marked this conversation as resolved.
Show resolved Hide resolved
// wait for clear to finish, VTextField sets _search to null
// then search computed triggers and updates _search to ''
nextTick(() => (cleared.value = false))
} else if (isFocused.value && !menu.value) {
menu.value = true
}

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

function onClear (e: MouseEvent) {
cleared.value = 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()
yuwu9145 marked this conversation as resolved.
Show resolved Hide resolved
e.stopPropagation()
}}
>
{ slots.clear
? slots.clear()
Expand Down