CommandMenu
A ⌘K command palette: search, grouped actions and keyboard navigation in a modal dialog.
Status: beta. Category: Navigation.
import { CommandMenu, Command, CommandInput, CommandList, CommandEmpty, CommandGroup } from '@glyphui/ui'
Exports: CommandMenu, Command, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandSeparator, useCommandMenuShortcut, commandMenuStyles.
Notes
- Items close the menu after onSelect by default; pass closeOnSelect={false} to keep it open.
- Shortcuts on items are display-only hints; bind the keys yourself if they should work globally.
Example: Command palette
Press ⌘K (or Ctrl+K) anywhere on the page.
import {
Button,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandMenu,
CommandSeparator,
Kbd,
useCommandMenuShortcut,
} from '@glyphui/ui'
import { CircleDot, FilePlus, Moon, Search, Settings2, Users } from 'lucide-react'
import { useState } from 'react'
export default function Example() {
const [open, setOpen] = useState(false)
const [last, setLast] = useState<string | null>(null)
useCommandMenuShortcut(setOpen)
return (
<div className="flex flex-wrap items-center gap-3">
<Button variant="outline" leftIcon={<Search />} onClick={() => setOpen(true)}>
Search
<Kbd className="ml-1">⌘K</Kbd>
</Button>
{last && <span className="text-small text-muted-foreground">Ran: {last}</span>}
<CommandMenu open={open} onOpenChange={setOpen}>
<CommandInput placeholder="Type a command or search…" />
<CommandList>
<CommandEmpty>No commands match.</CommandEmpty>
<CommandGroup heading="Issues">
<CommandItem icon={<FilePlus />} shortcut="C" onSelect={() => setLast('New issue')}>
New issue
</CommandItem>
<CommandItem icon={<CircleDot />} onSelect={() => setLast('My issues')}>
My issues
</CommandItem>
</CommandGroup>
<CommandSeparator />
<CommandGroup heading="Workspace">
<CommandItem icon={<Users />} onSelect={() => setLast('Invite people')}>
Invite people
</CommandItem>
<CommandItem
icon={<Moon />}
shortcut={['⌘', 'J']}
onSelect={() => setLast('Toggle dark mode')}
>
Toggle dark mode
</CommandItem>
<CommandItem
icon={<Settings2 />}
shortcut={['⌘', ',']}
onSelect={() => setLast('Settings')}
>
Settings
</CommandItem>
</CommandGroup>
</CommandList>
</CommandMenu>
</div>
)
}
Example: Inline
Command without the dialog, for search panels.
import { Command, CommandEmpty, CommandInput, CommandItem, CommandList } from '@glyphui/ui'
const docs = ['Button', 'Card', 'Combobox', 'DataTable', 'Form', 'Sidebar', 'Tabs']
export default function Example() {
return (
<Command className="max-w-sm rounded-lg border border-border shadow-md">
<CommandInput placeholder="Search components…" />
<CommandList>
<CommandEmpty>No components found.</CommandEmpty>
{docs.map((name) => (
<CommandItem key={name}>{name}</CommandItem>
))}
</CommandList>
</Command>
)
}
Live page: https://glyphui.xyz/components/command-menu