Skip to content

fix(VAutocomplete): do not emit update:search on blur-triggered reset#22771

Open
mixelburg wants to merge 1 commit intovuetifyjs:masterfrom
mixelburg:fix/VAutocomplete-update-search-on-blur
Open

fix(VAutocomplete): do not emit update:search on blur-triggered reset#22771
mixelburg wants to merge 1 commit intovuetifyjs:masterfrom
mixelburg:fix/VAutocomplete-update-search-on-blur

Conversation

@mixelburg
Copy link
Copy Markdown
Contributor

fixes #22767

Problem

When using v-model:search to power remote data fetching, selecting an item and clicking outside triggers a spurious update:search event with ''. This reloads the items list with an empty query, removing the selected item from the list and breaking the displayed value.

Root Cause

search was declared as useProxiedModel(props, 'search', ''), which automatically emits update:search whenever search.value changes. The isFocused watcher unconditionally sets search.value = '' on blur, triggering the emit even though no user input occurred.

Fix

Replace useProxiedModel for search with a private _search shallowRef + computed accessor. Only emit update:search when isFocused is true (matching the existing guard already used for menu/isPristine management). External prop changes are synced via a dedicated watch(() => props.search) watcher.

When isFocused transitions to false, the watcher unconditionally sets
search.value = '', which was being forwarded through useProxiedModel as
an update:search event. Users relying on update:search to fetch remote
items would then get an empty search, reloading their items list and
losing the current selection.

Replace useProxiedModel for search with a private _search shallowRef +
a computed accessor, and only emit update:search when isFocused is true
(same guard already used for menu/isPristine management). External prop
changes are synced in via a dedicated watch(() => props.search) watcher.

Fixes vuetifyjs#22767
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug Report][3.12.4] VAutocomplete emits update:search with empty string on blur, breaking remote-data selections

1 participant