CommandMenu() — ui Function Reference
Architecture documentation for the CommandMenu() function in command-menu.tsx from the ui codebase.
Entity Profile
Dependency Diagram
graph TD a6134ad6_6200_c7fe_1121_8dbccfb825e5["CommandMenu()"] f230e63c_c621_4fb0_5506_e74b21915cf5["command-menu.tsx"] a6134ad6_6200_c7fe_1121_8dbccfb825e5 -->|defined in| f230e63c_c621_4fb0_5506_e74b21915cf5 style a6134ad6_6200_c7fe_1121_8dbccfb825e5 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
apps/v4/components/command-menu.tsx lines 40–466
export function CommandMenu({
tree,
colors,
blocks,
navItems,
...props
}: React.ComponentProps<typeof Dialog> & {
tree: typeof source.pageTree
colors: ColorPalette[]
blocks?: { name: string; description: string; categories: string[] }[]
navItems?: { href: string; label: string }[]
}) {
const router = useRouter()
const pathname = usePathname()
const [config] = useConfig()
const currentBase = getCurrentBase(pathname)
const [open, setOpen] = React.useState(false)
const [renderDelayedGroups, setRenderDelayedGroups] = React.useState(false)
const [selectedType, setSelectedType] = React.useState<
"color" | "page" | "component" | "block" | null
>(null)
const [copyPayload, setCopyPayload] = React.useState("")
const { search, setSearch, query } = useDocsSearch({
type: "fetch",
})
const packageManager = config.packageManager || "pnpm"
// Track search queries with debouncing to avoid excessive tracking.
const searchTimeoutRef = React.useRef<NodeJS.Timeout | undefined>(undefined)
const lastTrackedQueryRef = React.useRef<string>("")
const trackSearchQuery = React.useCallback((query: string) => {
const trimmedQuery = query.trim()
// Only track if the query is different from the last tracked query and has content.
if (trimmedQuery && trimmedQuery !== lastTrackedQueryRef.current) {
lastTrackedQueryRef.current = trimmedQuery
trackEvent({
name: "search_query",
properties: {
query: trimmedQuery,
query_length: trimmedQuery.length,
},
})
}
}, [])
const handleSearchChange = React.useCallback(
(value: string) => {
// Clear existing timeout.
if (searchTimeoutRef.current) {
clearTimeout(searchTimeoutRef.current)
}
// Set new timeout to debounce both search and tracking.
searchTimeoutRef.current = setTimeout(() => {
React.startTransition(() => {
setSearch(value)
trackSearchQuery(value)
})
}, 500)
},
[setSearch, trackSearchQuery]
)
// Cleanup timeout on unmount.
React.useEffect(() => {
if (open) {
const frame = requestAnimationFrame(() => {
setRenderDelayedGroups(true)
})
return () => {
cancelAnimationFrame(frame)
}
}
setRenderDelayedGroups(false)
}, [open])
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does CommandMenu() do?
CommandMenu() is a function in the ui codebase, defined in apps/v4/components/command-menu.tsx.
Where is CommandMenu() defined?
CommandMenu() is defined in apps/v4/components/command-menu.tsx at line 40.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free