Skip to content

Commit

Permalink
fix(VSelect): replace onfocusout with onAfterleave (#17218)
Browse files Browse the repository at this point in the history
fixes #17214
  • Loading branch information
yuwu9145 committed May 3, 2023
1 parent 1f6b2b3 commit 36e75c2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
12 changes: 4 additions & 8 deletions packages/vuetify/src/components/VAutocomplete/VAutocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,19 +247,16 @@ export const VAutocomplete = genericComponent<new <
}

function onAfterLeave () {
if (isFocused.value) isPristine.value = true
if (isFocused.value) {
isPristine.value = true
vTextFieldRef.value?.focus()
}
}

function onFocusin (e: FocusEvent) {
isFocused.value = true
}

function onFocusout (e: FocusEvent) {
if (e.relatedTarget == null) {
vTextFieldRef.value?.focus()
}
}

const isSelecting = ref(false)

function select (item: InternalItem) {
Expand Down Expand Up @@ -370,7 +367,6 @@ export const VAutocomplete = genericComponent<new <
selectStrategy={ props.multiple ? 'independent' : 'single-independent' }
onMousedown={ (e: MouseEvent) => e.preventDefault() }
onFocusin={ onFocusin }
onFocusout={ onFocusout }
>
{ !displayItems.value.length && !props.hideNoData && (slots['no-data']?.() ?? (
<VListItem title={ t(props.noDataText) } />
Expand Down
12 changes: 4 additions & 8 deletions packages/vuetify/src/components/VCombobox/VCombobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,10 @@ export const VCombobox = genericComponent<new <
}
}
function onAfterLeave () {
if (isFocused.value) isPristine.value = true
if (isFocused.value) {
isPristine.value = true
vTextFieldRef.value?.focus()
}
}
function select (item: InternalItem) {
if (props.multiple) {
Expand Down Expand Up @@ -324,12 +327,6 @@ export const VCombobox = genericComponent<new <
isFocused.value = true
}

function onFocusout (e: FocusEvent) {
if (e.relatedTarget == null) {
vTextFieldRef.value?.focus()
}
}

watch(filteredItems, val => {
if (!val.length && props.hideNoData) menu.value = false
})
Expand Down Expand Up @@ -404,7 +401,6 @@ export const VCombobox = genericComponent<new <
selectStrategy={ props.multiple ? 'independent' : 'single-independent' }
onMousedown={ (e: MouseEvent) => e.preventDefault() }
onFocusin={ onFocusin }
onFocusout={ onFocusout }
>
{ !displayItems.value.length && !props.hideNoData && (slots['no-data']?.() ?? (
<VListItem title={ t(props.noDataText) } />
Expand Down
12 changes: 6 additions & 6 deletions packages/vuetify/src/components/VSelect/VSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,14 @@ export const VSelect = genericComponent<new <
menu.value = false
}
}
function onFocusin (e: FocusEvent) {
isFocused.value = true
}
function onFocusout (e: FocusEvent) {
if (e.relatedTarget == null) {
function onAfterLeave () {
if (isFocused.value) {
vTextFieldRef.value?.focus()
}
}
function onFocusin (e: FocusEvent) {
isFocused.value = true
}

useRender(() => {
const hasChips = !!(props.chips || slots.chip)
Expand Down Expand Up @@ -296,6 +296,7 @@ export const VSelect = genericComponent<new <
openOnClick={ false }
closeOnContentClick={ false }
transition={ props.transition }
onAfterLeave={ onAfterLeave }
{ ...props.menuProps }
>
{ hasList && (
Expand All @@ -305,7 +306,6 @@ export const VSelect = genericComponent<new <
selectStrategy={ props.multiple ? 'independent' : 'single-independent' }
onMousedown={ (e: MouseEvent) => e.preventDefault() }
onFocusin={ onFocusin }
onFocusout={ onFocusout }
>
{ !displayItems.value.length && !props.hideNoData && (slots['no-data']?.() ?? (
<VListItem title={ t(props.noDataText) } />
Expand Down

0 comments on commit 36e75c2

Please sign in to comment.