Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions packages/api-generator/src/locale/en/VCombobox.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"props": {
"alwaysFilter": "When enabled, dropdown list will always show items matching non-empty value within the field. Recommended when the list is meant to show suggestions rather than options to choose from. For optimal UX, should be combined with `:menu-icon=\"false\"` and `hide-selected`.",
"autoSelectFirst": "When searching, will always highlight the first option and select it on blur. `exact` will only highlight and select exact matches.",
"clearOnSelect": "Reset the search text when a selection is made while using the **multiple** prop.",
"itemChildren": "This property currently has **no effect**.",
Expand Down
1 change: 1 addition & 0 deletions packages/docs/src/data/new-in.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
},
"VCombobox": {
"props": {
"alwaysFilter": "3.10.4",
"autocomplete": "3.10.0",
"clearOnSelect": "3.5.0",
"listProps": "3.5.0"
Expand Down
7 changes: 6 additions & 1 deletion packages/vuetify/src/components/VCombobox/VCombobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type Value <T, ReturnObject extends boolean, Multiple extends boolean> =
: Val<T, ReturnObject> | null

export const makeVComboboxProps = propsFactory({
alwaysFilter: Boolean,
autoSelectFirst: {
type: [Boolean, String] as PropType<boolean | 'exact'>,
},
Expand Down Expand Up @@ -189,7 +190,11 @@ export const VCombobox = genericComponent<new <
: (props.multiple ? model.value.length : search.value.length)
})

const { filteredItems, getMatches } = useFilter(props, items, () => isPristine.value ? '' : search.value)
const { filteredItems, getMatches } = useFilter(
props,
items,
() => props.alwaysFilter || !isPristine.value ? search.value : ''
)

const displayItems = computed(() => {
if (props.hideSelected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,22 @@ describe('VCombobox', () => {
expect(model.value).toEqual(expected)
})

it('should show only matching items when reopening the menu if alwaysFilter is true', async () => {
const { element } = render(() => (
<VCombobox alwaysFilter items={['California', 'Colorado', 'Florida', 'Georgia', 'Texas', 'Wyoming']} />
))

await userEvent.click(element)
await userEvent.keyboard('c')
await expect(screen.findAllByRole('option')).resolves.toHaveLength(2)
await userEvent.keyboard('al')
await expect(screen.findAllByRole('option')).resolves.toHaveLength(1)
await userEvent.click(document.body)
await expect.poll(() => screen.queryAllByRole('option')).toHaveLength(0)
await userEvent.click(element)
await expect.poll(() => screen.queryAllByRole('option')).toHaveLength(1)
})

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