shadcn.io is not affiliated with official shadcn/ui
Command examples · Dialog
Simple Command Dialog for React
A button that opens a command dialog with a search field and three suggestions.
Three suggestions under one heading, Calendar, Search Emoji and Calculator, and a search field that filters them. Start here and add icons, shortcuts or more groups as the menu grows. 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.
What commands are in this menu?
One CommandGroup with the heading Suggestions holds three CommandItems: Calendar, Search Emoji and Calculator. Each item's text is its only content.
Should this be a Command or a Combobox?
Use a Command to run an action or jump somewhere. Use a Combobox when the choice is a value that stays in a form field.
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
- Simple Command MenuAn inline command menu with a search
- Simple Command PopoverA button that opens a command popover
- Simple Single Select ComboboxA single-select combobox that opens from
- Command Dialog Actions MenuA Quick Actions button that opens a
- Standard DialogA share dialog with a read-only link, a
- Command Dialog with BadgesA Browse Components button that opens a