Skip to content

Commit

Permalink
refactor(VSelects): implement better fix for #18556
Browse files Browse the repository at this point in the history
current implementation causes menu to hide and show during search
causing a menu flicker
  • Loading branch information
johnleider committed Feb 27, 2024
1 parent c0f061b commit 12c9e27
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 27 deletions.
12 changes: 3 additions & 9 deletions packages/vuetify/src/components/VAutocomplete/VAutocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -396,16 +396,10 @@ export const VAutocomplete = genericComponent<new <
}
})

watch(displayItems, (val, oldVal) => {
if (!isFocused.value) return
watch(() => props.items, val => {
if (!isFocused.value || !val.length || menu.value) return

if (!val.length && props.hideNoData) {
menu.value = false
}

if (!oldVal.length && val.length) {
menu.value = true
}
menu.value = true
})

useRender(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,19 @@ describe('VAutocomplete', () => {
})
})

// https://github.com/vuetifyjs/vuetify/issues/18556
it('should show menu if focused and items are added', () => {
cy
.mount(props => (<VAutocomplete { ...props } />))
.get('.v-autocomplete input')
.focus()
.get('.v-overlay')
.should('not.exist')
.setProps({ items: ['Foo', 'Bar'] })
.get('.v-overlay')
.should('exist')
})

describe('Showcase', () => {
generate({ stories })
})
Expand Down
12 changes: 3 additions & 9 deletions packages/vuetify/src/components/VCombobox/VCombobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -423,16 +423,10 @@ export const VCombobox = genericComponent<new <
}
})

watch(displayItems, (val, oldVal) => {
if (!isFocused.value) return
watch(() => props.items, val => {
if (!isFocused.value || !val.length || menu.value) return

if (!val.length && props.hideNoData) {
menu.value = false
}

if (!oldVal.length && val.length) {
menu.value = true
}
menu.value = true
})

useRender(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,19 @@ describe('VCombobox', () => {
})
})

// https://github.com/vuetifyjs/vuetify/issues/18556
it('should show menu if focused and items are added', () => {
cy
.mount(props => (<VCombobox { ...props } />))
.get('.v-combobox input')
.focus()
.get('.v-overlay')
.should('not.exist')
.setProps({ items: ['Foo', 'Bar'] })
.get('.v-overlay')
.should('exist')
})

describe('Showcase', () => {
generate({ stories })
})
Expand Down
12 changes: 3 additions & 9 deletions packages/vuetify/src/components/VSelect/VSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,16 +304,10 @@ export const VSelect = genericComponent<new <
}
})

watch(displayItems, (val, oldVal) => {
if (!isFocused.value) return
watch(() => props.items, val => {
if (!isFocused.value || !val.length || menu.value) return

if (!val.length && props.hideNoData) {
menu.value = false
}

if (!oldVal.length && val.length) {
menu.value = true
}
menu.value = true
})

useRender(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,19 @@ describe('VSelect', () => {
})
})

// https://github.com/vuetifyjs/vuetify/issues/18556
it('should show menu if focused and items are added', () => {
cy
.mount(props => (<VSelect { ...props } />))
.get('.v-select input')
.focus()
.get('.v-overlay')
.should('not.exist')
.setProps({ items: ['Foo', 'Bar'] })
.get('.v-overlay')
.should('exist')
})

describe('Showcase', () => {
generate({ stories })
})
Expand Down

0 comments on commit 12c9e27

Please sign in to comment.