shadcn.io is not affiliated with official shadcn/ui
Command examples · Dialog
Command Dialog with Icons and Shortcuts for React
A button that opens a command dialog with icons on every item and shortcut hints on the settings.
Suggestions with icons, then Settings with shortcut hints such as ⌘P. The icons help people scan the list, and the hints teach the keys for next time. The Open Command Menu button opens the menu in a CommandDialog over the page, and Escape closes it. In React, Base UI handles the keyboard navigation.
Preview
Installation
FAQ
How does this dialog open?
The Open Command Menu button sets an open state to true, and CommandDialog takes that state with its change handler, so Escape or a click outside sets it back. The dialog has a visually hidden title and description.
The Command goes straight inside CommandDialog.
Which items show an icon, and which show a shortcut?
Every item has an icon. The Suggestions group holds Calendar, Search Emoji and Calculator. The Settings group holds Profile, Billing and Settings, each with a shortcut label: ⌘P, ⌘B and ⌘S.
Do those shortcut hints fire the keys?
No. CommandShortcut is a label at the end of the row, and the item's check mark stays hidden while it's there. Listen for those keys yourself if Profile, Billing or Settings should run from the keyboard.
What appears when nothing matches the search?
CommandEmpty in the list says "No results found." It shows only when the search leaves nothing.
How do I run an item from this dialog in React?
These items don't run anything yet.
Pass onSelect to each CommandItem. Close the dialog in the same handler.
How do the keys work in this dialog?
The arrow keys move through the items, Enter runs the highlighted one, and typing filters the list. Escape closes CommandDialog, and focus goes back to the button. CommandInput shows "Type a command or search..." until someone types.
Command filters and ranks the items by their text on its own.
Related
- Command with Icons and ShortcutsAn inline command menu with icons on
- Command Popover with Icons and ShortcutsA button that opens a command popover
- Command Actions MenuAn inline command menu of quick and file
- Command Dialog Actions MenuA Quick Actions button that opens a
- With Item Icons ComboboxA combobox with an icon beside each
- Command Dialog with BadgesA Browse Components button that opens a