Skip to content

Commit 9888624

Browse files
committed
fix(VAutocomplete, VCombobox): skip subheader for auto-select-first
1 parent f49803a commit 9888624

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

packages/vuetify/src/components/VAutocomplete/VAutocomplete.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable complexity */
12
// Styles
23
import './VAutocomplete.sass'
34

@@ -170,6 +171,12 @@ export const VAutocomplete = genericComponent<new <
170171
!listHasFocus.value
171172
})
172173

174+
const firstSelectableItem = computed(() => {
175+
return highlightFirst.value
176+
? displayItems.value.find(x => x.type === 'item' && !x.props.disabled)
177+
: null
178+
})
179+
173180
const menuDisabled = computed(() => (
174181
(props.hideNoData && !displayItems.value.length) ||
175182
form.isReadonly.value || form.isDisabled.value
@@ -235,9 +242,10 @@ export const VAutocomplete = genericComponent<new <
235242
if (
236243
highlightFirst.value &&
237244
['Enter', 'Tab'].includes(e.key) &&
238-
!model.value.some(({ value }) => value === displayItems.value[0].value)
245+
firstSelectableItem.value &&
246+
!model.value.some(({ value }) => value === firstSelectableItem.value!.value)
239247
) {
240-
select(displayItems.value[0])
248+
select(firstSelectableItem.value)
241249
}
242250

243251
if (e.key === 'ArrowDown' && highlightFirst.value) {
@@ -503,7 +511,7 @@ export const VAutocomplete = genericComponent<new <
503511
const itemProps = mergeProps(item.props, {
504512
ref: itemRef,
505513
key: item.value,
506-
active: (highlightFirst.value && index === 0) ? true : undefined,
514+
active: (highlightFirst.value && item.value === firstSelectableItem.value?.value) ? true : undefined,
507515
onClick: () => select(item, null),
508516
})
509517

packages/vuetify/src/components/VCombobox/VCombobox.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ export const VCombobox = genericComponent<new <
242242
!listHasFocus.value
243243
})
244244

245+
const firstSelectableItem = computed(() => {
246+
return highlightFirst.value
247+
? displayItems.value.find(x => x.type === 'item' && !x.props.disabled)
248+
: null
249+
})
250+
245251
const listRef = ref<VList>()
246252
const listEvents = useScrolling(listRef, vTextFieldRef)
247253
function onClear (e: MouseEvent) {
@@ -292,9 +298,10 @@ export const VCombobox = genericComponent<new <
292298

293299
if (highlightFirst.value &&
294300
['Enter', 'Tab'].includes(e.key) &&
295-
!model.value.some(({ value }) => value === displayItems.value[0].value)
301+
firstSelectableItem.value &&
302+
!model.value.some(({ value }) => value === firstSelectableItem.value!.value)
296303
) {
297-
select(filteredItems.value[0])
304+
select(firstSelectableItem.value)
298305
}
299306

300307
if (e.key === 'ArrowDown' && highlightFirst.value) {
@@ -566,7 +573,7 @@ export const VCombobox = genericComponent<new <
566573
const itemProps = mergeProps(item.props, {
567574
ref: itemRef,
568575
key: item.value,
569-
active: (highlightFirst.value && index === 0) ? true : undefined,
576+
active: (highlightFirst.value && item.value === firstSelectableItem.value?.value) ? true : undefined,
570577
onClick: () => select(item, null),
571578
})
572579

0 commit comments

Comments
 (0)