Command menu
The ⌘K palette: search every action and page, then run one with Enter.
Installation
npm i @uisatin/uiimport { CommandMenu } from '@uisatin/ui/command-menu'About 29.6 kB of JavaScript, minified and gzipped, with what it imports (React aside). The stylesheet is one file for every component.
npx shadcn@latest add https://uisatin.dev/r/command-menu.json https://uisatin.dev/r/search-bar.jsonAdds command-menu.tsx, command-menu.tsx, dropdown.tsx, kbd.tsx, labels.tsx, pointer-modality.tsx and search-bar.tsx to components/ui and installs iconoir-react and radix-ui.
First time with Satin? Set it up once, styles and fonts included, with the installation guide.
API Reference
The CommandMenu component wraps the Radix dialog in a div with a search input (role="combobox") and a listbox of grouped commands. ⌘K or Ctrl+K toggles it unless hotkey is off. For a menu that changes what it shows: query / onQueryChange control the search (emptied as the menu closes), an item with keepOpen runs without closing it, header goes above the search row, children take the list's place and footer replaces the key hints (compose it from KbdHint).
| Prop | Type | Default |
|---|---|---|
groups | CommandGroup[] | — |
item.label | string | — |
item.icon | ReactNode | — |
item.description | string | — |
item.shortcut | string | — |
item.onSelect | () => void | — |
hotkey | boolean | true |
hints | boolean | true |
placeholder | string | — |
open | boolean | — |
defaultOpen | boolean | false |
onOpenChange | (open: boolean) => void | — |
emptyText | (query: string) => ReactNode | — |
modal | boolean | true |
item.keepOpen | boolean | false |
query | string | — |
onQueryChange | (query: string) => void | — |
header | ReactNode | — |
footer | ReactNode | — |
children | ReactNode | — |
className | string | — |
ref | Ref<HTMLElement> | — |
...props | ComponentProps<typeof Dialog.Content>Other attributes go to the Radix Dialog.Content part | — |
Accessibility
A Radix dialog titled "Command menu" for screen readers. The search input is a combobox named "Search commands" that points at the highlighted row with aria-activedescendant; the rows are options in a listbox named "Commands", grouped under their headings. The key hints in the footer are hidden.
| Key | Action |
|---|---|
| ⌘KorCtrl+K | Opens or closes the menu from anywhere on the page, unless hotkey is off. |
| ↑or↓ | Moves the highlight, wrapping at the ends. |
| Enter | Runs the highlighted command and closes the menu. |
| TaborShift+Tab | Keep focus inside the menu while it is modal (the default). |
| Esc | Closes the menu and returns focus to where it was. |
Something wrong or missing on this page?
Report a problemSuggest an improvement