Skip to content

Commit 4bae0bc

Browse files
committed
fix(VList): ignore invalid itemType values
fixes #21728
1 parent 34b53f1 commit 4bae0bc

File tree

3 files changed

+34
-23
lines changed

3 files changed

+34
-23
lines changed

packages/vuetify/src/components/VList/VList.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,21 @@ import type { GenericProps, SelectItemKey } from '@/util'
4242

4343
export interface InternalListItem<T = any> extends ListItem<T> {}
4444

45+
const itemTypes = new Set(['item', 'divider', 'subheader'])
46+
4547
function transformItem (props: ItemProps, item: any): ListItem {
46-
const type = getPropertyFromItem(item, props.itemType, 'item')
4748
const title = isPrimitive(item) ? item : getPropertyFromItem(item, props.itemTitle)
4849
const value = isPrimitive(item) ? item : getPropertyFromItem(item, props.itemValue, undefined)
4950
const children = getPropertyFromItem(item, props.itemChildren)
5051
const itemProps = props.itemProps === true
5152
? omit(item, ['children'])
5253
: getPropertyFromItem(item, props.itemProps)
5354

55+
let type = getPropertyFromItem(item, props.itemType, 'item')
56+
if (!itemTypes.has(type)) {
57+
type = 'item'
58+
}
59+
5460
const _props = {
5561
title,
5662
value,

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

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,15 @@ export const makeItemsProps = propsFactory({
5959
valueComparator: Function as PropType<typeof deepEqual>,
6060
}, 'list-items')
6161

62-
export function transformItem (props: Omit<ItemProps, 'items'>, item: any): ListItem {
62+
const itemTypes = new Set(['item', 'divider', 'subheader'])
63+
64+
export function transformItem (
65+
props: Pick<ItemProps, typeof transformItem.neededProps[number]>,
66+
item: any
67+
): ListItem {
6368
const title = getPropertyFromItem(item, props.itemTitle, item)
6469
const value = getPropertyFromItem(item, props.itemValue, title)
6570
const children = getPropertyFromItem(item, props.itemChildren)
66-
const type = getPropertyFromItem(item, props.itemType, 'item')
6771
const itemProps = props.itemProps === true
6872
? typeof item === 'object' && item != null && !Array.isArray(item)
6973
? 'children' in item
@@ -72,6 +76,11 @@ export function transformItem (props: Omit<ItemProps, 'items'>, item: any): List
7276
: undefined
7377
: getPropertyFromItem(item, props.itemProps)
7478

79+
let type = getPropertyFromItem(item, props.itemType, 'item')
80+
if (!itemTypes.has(type)) {
81+
type = 'item'
82+
}
83+
7584
const _props = {
7685
title,
7786
value,
@@ -88,16 +97,20 @@ export function transformItem (props: Omit<ItemProps, 'items'>, item: any): List
8897
}
8998
}
9099

91-
export function transformItems (props: Omit<ItemProps, 'items'>, items: ItemProps['items']) {
92-
const _props = pick(props, [
93-
'itemTitle',
94-
'itemValue',
95-
'itemChildren',
96-
'itemProps',
97-
'itemType',
98-
'returnObject',
99-
'valueComparator',
100-
])
100+
transformItem.neededProps = [
101+
'itemTitle',
102+
'itemValue',
103+
'itemChildren',
104+
'itemProps',
105+
'itemType',
106+
] as const
107+
108+
export function transformItems (
109+
props: Pick<ItemProps, typeof transformItem.neededProps[number]>,
110+
items: ItemProps['items']
111+
) {
112+
// avoid reactive access in the loop
113+
const _props = pick(props, transformItem.neededProps)
101114

102115
const array: ListItem[] = []
103116
for (const item of items) {
@@ -144,15 +157,7 @@ export function useItems (props: ItemProps) {
144157
const _returnObject = props.returnObject
145158
const hasValueComparator = !!props.valueComparator
146159
const valueComparator = props.valueComparator || deepEqual
147-
const _props = pick(props, [
148-
'itemTitle',
149-
'itemValue',
150-
'itemChildren',
151-
'itemProps',
152-
'itemType',
153-
'returnObject',
154-
'valueComparator',
155-
])
160+
const _props = pick(props, transformItem.neededProps)
156161

157162
const returnValue: ListItem[] = []
158163
main: for (const v of value) {

packages/vuetify/src/util/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ type MaybePick<
225225
export function pick<
226226
T extends object,
227227
U extends Extract<keyof T, string>
228-
> (obj: T, paths: U[]): MaybePick<T, U> {
228+
> (obj: T, paths: readonly U[]): MaybePick<T, U> {
229229
const found: any = {}
230230

231231
for (const key of paths) {

0 commit comments

Comments
 (0)