Skip to content

Commit 339bd45

Browse files
arvi-nagarajKaelWD
andauthored
fix(VSelect): dont open menu on its own when items change (#21247)
fixes #21205 Co-authored-by: Kael <[email protected]>
1 parent ea7d80b commit 339bd45

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

packages/vuetify/src/components/VSelect/VSelect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ export const VSelect = genericComponent<new <
367367
watch(() => props.items, (newVal, oldVal) => {
368368
if (menu.value) return
369369

370-
if (isFocused.value && !oldVal.length && newVal.length) {
370+
if (isFocused.value && props.hideNoData && !oldVal.length && newVal.length) {
371371
menu.value = true
372372
}
373373
})

packages/vuetify/src/components/VSelect/__tests__/VSelect.spec.browser.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { VListItem } from '@/components/VList'
66
// Utilities
77
import { commands, generate, render, screen, userEvent } from '@test'
88
import { getAllByRole } from '@testing-library/vue'
9-
import { cloneVNode, ref } from 'vue'
9+
import { cloneVNode, nextTick, ref } from 'vue'
1010

1111
const variants = ['underlined', 'outlined', 'filled', 'solo', 'plain'] as const
1212
const densities = ['default', 'comfortable', 'compact'] as const
@@ -587,16 +587,32 @@ describe('VSelect', () => {
587587
})
588588

589589
// https://github.com/vuetifyjs/vuetify/issues/18556
590-
it('should show menu if focused and items are added', async () => {
591-
const { rerender } = render(VSelect)
590+
// https://github.com/vuetifyjs/vuetify/issues/21205
591+
it('should show menu if focused and items are added when hideNoData is true"', async () => {
592+
const items = ref()
593+
render(() => <VSelect items={ items.value } hideNoData />)
592594

593595
await userEvent.keyboard('{Tab}')
594596
expect(screen.queryByRole('listbox')).toBeNull()
595597

596-
await rerender({ items: ['Foo', 'Bar'] })
598+
items.value = ['Foo', 'Bar']
599+
await nextTick()
597600
await expect.poll(() => screen.queryByRole('listbox')).toBeVisible()
598601
})
599602

603+
// https://github.com/vuetifyjs/vuetify/issues/21205
604+
it('should not show menu if focused and items are added when hideNoData is false', async () => {
605+
const items = ref()
606+
render(() => <VSelect items={ items.value } />)
607+
608+
await userEvent.keyboard('{Tab}')
609+
expect(screen.queryByRole('listbox')).toBeNull()
610+
611+
items.value = ['Foo', 'Bar']
612+
await nextTick()
613+
await expect.poll(() => screen.queryByRole('listbox')).toBeNull()
614+
})
615+
600616
// https://github.com/vuetifyjs/vuetify/issues/19346
601617
it('should not show menu when focused and existing non-empty items are changed', async () => {
602618
const { element, rerender } = render(VSelect, {

0 commit comments

Comments
 (0)