- Label
- Icon label
- Field
- Form
- Frontmatter form
- Questionnaire
- Input
- Input group
- Input OTP
- Password input
- Password strength
- Code input
- Number field
- Tag input
- Textarea
- Checkbox
- Radio group
- Language toggle group
- Emoji appearance toggle group
- Emoji picker
- Avatar picker
- AI provider picker
- Select
- Native select
- Combobox
- Language combobox
- Slider
- Calendar
- Switch
- Alert
- Avatar
- Badge
- Card
- AI provider card
- Model info card
- Model list
- Empty
- Item
- Tree item
- File tree
- Icon media
- File type icon
- Font preview
- Image preview
- Kbd
- Table
- Data table
- Data table column header
- Chart
- Code Block
- Code card
- Markdown view
- Attachment
- Bubble
- Marker
- Message
- Chat message
- Chat suggestion item
- Message scroller
- Trace
- Progress
- Spinner
- Sonner
- Toast
- Unsaved changes toolbar
- Unsaved indicator
- Status indicator
- Permission card
- Separator
- Skeleton
- Animated grid pattern
- Meteors
A command palette for jumping to a target: a CommandDialog holding a Command that reports the chosen item's value and closes.
Installation#
pnpm dlx shadcn@latest add @zui/command-menuThe CLI writes components/navigation/command-menu.tsx and installs
Command with the items it needs.
Usage#
import { CommandMenu, CommandMenuItem } from '@/components/navigation/command-menu';
import { Button } from '@/components/ui/button';
import { CommandEmpty, CommandInput, CommandList } from '@/components/ui/command';
import { Text } from '@/components/ui/text';<Button variant="outline" onPress={() => setOpen(true)}>
<Text>Open menu</Text>
</Button>
<CommandMenu open={open} onOpenChange={setOpen} onValueChange={setValue}>
<CommandInput placeholder="Jump to file..." />
<CommandList>
<CommandEmpty>No file found.</CommandEmpty>
<CommandMenuItem value="page.tsx">
<Text>page.tsx</Text>
</CommandMenuItem>
</CommandList>
</CommandMenu>Compose CommandInput, CommandList, CommandEmpty and the items as children, and open the menu from a control
of your own, such as a button. The dialog draws in a portal, so the app needs a PortalHost, as for
Dialog.
Composition#
CommandMenu
|-- CommandInput
`-- CommandList
|-- CommandEmpty
`-- CommandMenuItemAPI reference#
CommandMenu#
Takes every prop of CommandDialog except onOpenChange, which is
redefined, plus:
| Prop | Type | Default |
|---|---|---|
onOpenChange | (open: boolean) => void | - |
onValueChange | (value: string) => void | - |
It defaults CommandDialog's title to 'Command menu' and description to 'Search for a target to jump to.',
which a screen reader reads though they are not drawn. onOpenChange is called with false after an item is
chosen.
CommandMenuItem#
Takes every prop of CommandItem except value, which is required here:
| Prop | Type | Default |
|---|---|---|
value | string | required |
Choosing it runs the item's own onSelect if given, then reports value through the menu's onValueChange and
closes the dialog. The typed text is matched against value.
Differences from the web#
- The web's
useCommandShortcuthook, which opens the menu on Cmd+K or Ctrl+K, is not ported, since a phone has no such key; open the menu from a control. - Each item's label is a Text child, where the web's item takes the string itself.
- The web's
data-slotattributes are not set; a View takes no data attributes.