Skip to content

Commit 18ac731

Browse files
authored
feat(filter): keep dividers and subheaders (#21822)
resolves #7424
1 parent 27dc68c commit 18ac731

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/vuetify/src/composables/filter.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,17 @@ export function filterItems (
8686
noFilter?: boolean
8787
},
8888
) {
89-
const array: { index: number, matches: Record<string, FilterMatchArrayMultiple | undefined> }[] = []
89+
type FilterResult = { index: number, matches: Record<string, FilterMatchArrayMultiple | undefined>, type?: 'divider' | 'subheader' }
90+
const array: FilterResult[] = []
9091
// always ensure we fall back to a functioning filter
9192
const filter = options?.default ?? defaultFilter
9293
const keys = options?.filterKeys ? wrapInArray(options.filterKeys) : false
9394
const customFiltersLength = Object.keys(options?.customKeyFilter ?? {}).length
9495

9596
if (!items?.length) return array
9697

98+
let lookAheadItem: FilterResult | null = null
99+
97100
loop:
98101
for (let i = 0; i < items.length; i++) {
99102
const [item, transformed = item] = wrapInArray(items[i]) as readonly [InternalItem, {}]
@@ -104,6 +107,11 @@ export function filterItems (
104107
if ((query || customFiltersLength > 0) && !options?.noFilter) {
105108
if (typeof item === 'object') {
106109
if (item.type === 'divider' || item.type === 'subheader') {
110+
if (lookAheadItem?.type === 'divider' && item.type === 'subheader') {
111+
array.push(lookAheadItem) // divider before subheader
112+
}
113+
114+
lookAheadItem = { index: i, matches: { }, type: item.type }
107115
continue
108116
}
109117

@@ -151,6 +159,11 @@ export function filterItems (
151159
) continue
152160
}
153161

162+
if (lookAheadItem) {
163+
array.push(lookAheadItem)
164+
lookAheadItem = null
165+
}
166+
154167
array.push({ index: i, matches: { ...defaultMatches, ...customMatches } })
155168
}
156169

0 commit comments

Comments
 (0)