mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-20 15:01:46 +01:00
feat(CommandPalette): handle filter attribute in groups (#871)
This commit is contained in:
@@ -237,7 +237,8 @@ export default defineComponent({
|
||||
}
|
||||
for (const key in groupedCommands) {
|
||||
const group = props.groups.find(group => group.key === key)
|
||||
const commands = groupedCommands[key].slice(0, options.value.resultLimit).map((result) => {
|
||||
|
||||
let commands = groupedCommands[key].map((result) => {
|
||||
const { item, ...data } = result
|
||||
|
||||
return {
|
||||
@@ -246,12 +247,22 @@ export default defineComponent({
|
||||
} as Command
|
||||
})
|
||||
|
||||
groups.push({ ...group, commands })
|
||||
if (group.filter && typeof group.filter === 'function') {
|
||||
commands = group.filter(query.value, commands)
|
||||
}
|
||||
|
||||
groups.push({ ...group, commands: commands.slice(0, options.value.resultLimit) })
|
||||
}
|
||||
|
||||
for (const group of props.groups) {
|
||||
if (group.search && searchResults.value[group.key]?.length) {
|
||||
groups.push({ ...group, commands: (searchResults.value[group.key] || []).slice(0, options.value.resultLimit) })
|
||||
let commands = (searchResults.value[group.key] || [])
|
||||
|
||||
if (group.filter && typeof group.filter === 'function') {
|
||||
commands = group.filter(query.value, commands)
|
||||
}
|
||||
|
||||
groups.push({ ...group, commands: commands.slice(0, options.value.resultLimit) })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1
src/runtime/types/command-palette.d.ts
vendored
1
src/runtime/types/command-palette.d.ts
vendored
@@ -23,5 +23,6 @@ export interface Group {
|
||||
inactive?: string
|
||||
commands?: Command[]
|
||||
search?: Function
|
||||
filter?: Function
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user