Skip to content

Commit 2217337

Browse files
committed
chore(Kbar): results fix
1 parent 81a1d68 commit 2217337

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

components/KBar/Results.tsx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useMemo } from 'react'
22

33
import { KBarResults, useMatches } from 'kbar'
4+
import type { ActionImpl } from 'kbar'
45

56
import ResultItem from './ResultItem'
67

@@ -10,20 +11,29 @@ const Results = () => {
1011
const { results } = useMatches()
1112

1213
const flattened = useMemo(() => {
13-
return results.reduce((acc: any[], curr: any) => {
14-
if (typeof curr === 'string') {
15-
acc.push(curr)
16-
} else {
17-
acc.push(curr.name)
18-
acc.push(...curr.actions)
19-
}
20-
return acc
21-
}, [])
14+
const flattenActions = (actions: (string | ActionImpl)[]) => {
15+
return actions.reduce((acc: any[], curr: string | ActionImpl) => {
16+
if (typeof curr === 'string') {
17+
acc.push(curr)
18+
} else {
19+
acc.push(curr)
20+
21+
if (curr.children && curr.children.length > 0) {
22+
acc.push(...flattenActions(curr.children))
23+
}
24+
}
25+
return acc
26+
}, [])
27+
}
28+
29+
return flattenActions(results)
2230
}, [results])
2331

2432
return (
2533
<KBarResults
26-
items={flattened.filter((i: string) => i !== NO_GROUP)}
34+
items={flattened.filter(
35+
(i: any) => typeof i !== 'string' || i !== NO_GROUP,
36+
)}
2737
onRender={({ item, active }) =>
2838
typeof item === 'string' ? (
2939
<div className="px-4 py-2 text-2xs uppercase text-gray-400 dark:text-gray-600 bg-white dark:bg-black-600">

0 commit comments

Comments
 (0)