Skip to content

Commit eaa4d15

Browse files
committed
feat(VSelects): add itemType prop
closes #21666
1 parent dd98067 commit eaa4d15

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,13 +495,13 @@ export const VAutocomplete = genericComponent<new <
495495
onClick: () => select(item, null),
496496
})
497497

498-
if (item.raw?.type === 'divider') {
498+
if (item.type === 'divider') {
499499
return slots.divider?.({ props: item.raw, index }) ?? (
500500
<VDivider { ...item.props } key={ `divider-${index}` } />
501501
)
502502
}
503503

504-
if (item.raw?.type === 'subheader') {
504+
if (item.type === 'subheader') {
505505
return slots.subheader?.({ props: item.raw, index }) ?? (
506506
<VListSubheader { ...item.props } key={ `subheader-${index}` } />
507507
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,13 +541,13 @@ export const VCombobox = genericComponent<new <
541541
onClick: () => select(item, null),
542542
})
543543

544-
if (item.raw?.type === 'divider') {
544+
if (item.type === 'divider') {
545545
return slots.divider?.({ props: item.raw, index }) ?? (
546546
<VDivider { ...item.props } key={ `divider-${index}` } />
547547
)
548548
}
549549

550-
if (item.raw?.type === 'subheader') {
550+
if (item.type === 'subheader') {
551551
return slots.subheader?.({ props: item.raw, index }) ?? (
552552
<VListSubheader { ...item.props } key={ `subheader-${index}` } />
553553
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,13 +470,13 @@ export const VSelect = genericComponent<new <
470470
onClick: () => select(item, null),
471471
})
472472

473-
if (item.raw?.type === 'divider') {
473+
if (item.type === 'divider') {
474474
return slots.divider?.({ props: item.raw, index }) ?? (
475475
<VDivider { ...item.props } key={ `divider-${index}` } />
476476
)
477477
}
478478

479-
if (item.raw?.type === 'subheader') {
479+
if (item.type === 'subheader') {
480480
return slots.subheader?.({ props: item.raw, index }) ?? (
481481
<VListSubheader { ...item.props } key={ `subheader-${index}` } />
482482
)

packages/vuetify/src/composables/filter.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export interface FilterProps {
3535
export interface InternalItem<T = any> {
3636
value: any
3737
raw: T
38+
type?: string
3839
}
3940

4041
// Composables
@@ -102,7 +103,7 @@ export function filterItems (
102103

103104
if ((query || customFiltersLength > 0) && !options?.noFilter) {
104105
if (typeof item === 'object') {
105-
if (['divider', 'subheader'].includes(item.raw?.type)) {
106+
if (item.type === 'divider' || item.type === 'subheader') {
106107
continue
107108
}
108109

packages/vuetify/src/composables/list-items.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export interface ListItem<T = any> extends InternalItem<T> {
1414
title: string
1515
value: any
1616
}
17-
children?: ListItem<T>[]
17+
children: ListItem<T>[] | undefined
18+
type: string
1819
}
1920

2021
export interface ItemProps {
@@ -23,6 +24,7 @@ export interface ItemProps {
2324
itemValue: SelectItemKey
2425
itemChildren: SelectItemKey
2526
itemProps: SelectItemKey
27+
itemType: SelectItemKey
2628
returnObject: boolean
2729
valueComparator: typeof deepEqual | undefined
2830
}
@@ -49,6 +51,10 @@ export const makeItemsProps = propsFactory({
4951
type: [Boolean, String, Array, Function] as PropType<SelectItemKey>,
5052
default: 'props',
5153
},
54+
itemType: {
55+
type: [Boolean, String, Array, Function] as PropType<SelectItemKey>,
56+
default: 'type',
57+
},
5258
returnObject: Boolean,
5359
valueComparator: Function as PropType<typeof deepEqual>,
5460
}, 'list-items')
@@ -57,6 +63,7 @@ export function transformItem (props: Omit<ItemProps, 'items'>, item: any): List
5763
const title = getPropertyFromItem(item, props.itemTitle, item)
5864
const value = getPropertyFromItem(item, props.itemValue, title)
5965
const children = getPropertyFromItem(item, props.itemChildren)
66+
const type = getPropertyFromItem(item, props.itemType, 'item')
6067
const itemProps = props.itemProps === true
6168
? typeof item === 'object' && item != null && !Array.isArray(item)
6269
? 'children' in item
@@ -72,10 +79,11 @@ export function transformItem (props: Omit<ItemProps, 'items'>, item: any): List
7279
}
7380

7481
return {
82+
type,
7583
title: String(_props.title ?? ''),
7684
value: _props.value,
7785
props: _props,
78-
children: Array.isArray(children) ? transformItems(props, children) : undefined,
86+
children: type === 'item' && Array.isArray(children) ? transformItems(props, children) : undefined,
7987
raw: item,
8088
}
8189
}
@@ -86,6 +94,7 @@ export function transformItems (props: Omit<ItemProps, 'items'>, items: ItemProp
8694
'itemValue',
8795
'itemChildren',
8896
'itemProps',
97+
'itemType',
8998
'returnObject',
9099
'valueComparator',
91100
])
@@ -140,6 +149,7 @@ export function useItems (props: ItemProps) {
140149
'itemValue',
141150
'itemChildren',
142151
'itemProps',
152+
'itemType',
143153
'returnObject',
144154
'valueComparator',
145155
])

0 commit comments

Comments
 (0)