diff --git a/components/KBar/Results.tsx b/components/KBar/Results.tsx index 9ba63fca..1fb705c5 100644 --- a/components/KBar/Results.tsx +++ b/components/KBar/Results.tsx @@ -1,6 +1,7 @@ import { useMemo } from 'react' import { KBarResults, useMatches } from 'kbar' +import type { ActionImpl } from 'kbar' import ResultItem from './ResultItem' @@ -10,20 +11,29 @@ const Results = () => { const { results } = useMatches() const flattened = useMemo(() => { - return results.reduce((acc: any[], curr: any) => { - if (typeof curr === 'string') { - acc.push(curr) - } else { - acc.push(curr.name) - acc.push(...curr.actions) - } - return acc - }, []) + const flattenActions = (actions: (string | ActionImpl)[]) => { + return actions.reduce((acc: any[], curr: string | ActionImpl) => { + if (typeof curr === 'string') { + acc.push(curr) + } else { + acc.push(curr) + + if (curr.children && curr.children.length > 0) { + acc.push(...flattenActions(curr.children)) + } + } + return acc + }, []) + } + + return flattenActions(results) }, [results]) return ( i !== NO_GROUP)} + items={flattened.filter( + (i: any) => typeof i !== 'string' || i !== NO_GROUP, + )} onRender={({ item, active }) => typeof item === 'string' ? (