shadcn.io is not affiliated with official shadcn/ui
Command examples · Popover
Command Popover with Separators for React
A Search Files button that opens a command popover with recent files, folders and media split by separators.
Recent files, folders and media in three groups, with a line between each. Add separators when the headings alone don't break a long list up enough. The Search Files button opens the menu in a Popover below the button, so the menu stays next to what it acts on. In React, Base UI handles the keyboard navigation.
Preview
Installation
FAQ
How is this menu anchored to the button?
The Search Files button is the trigger, and the panel opens below it, lined up with its start edge. The panel is 400px wide, never wider than the screen, and has no padding, so the Command fills it. A visually hidden PopoverTitle names it.
PopoverTrigger renders the button through render, and PopoverContent sets align="start".
Where does the line between groups sit?
A CommandSeparator goes before every group but the first, so the lines fall after Recent and after Folders. Each group keeps its own heading: Recent, Folders and Media.
What does each file row contain?
Every CommandItem starts with a decorative icon, then a span for the name: Document.pdf, Photo.jpg, Projects, Documents, Video.mp4 and Song.mp3. The icons are File, Image, Folder (twice), Video and Music.
What appears when nothing matches the search?
CommandEmpty in the list says "No files found." It shows only when the search leaves nothing.
How do I run an item from this menu in React?
These items don't run anything yet.
Pass onSelect to each CommandItem.
How do the keys work in this menu?
The arrow keys move through the items, Enter runs the highlighted one, and typing filters the list. Escape or a click outside closes the popover, and focus goes back to the button. CommandInput shows "Search files..." until someone types.
Command filters and ranks the items by their text on its own.
Related
- Command with SeparatorsAn inline command menu with recent files
- Command Dialog with SeparatorsA Search Files button that opens a
- Command with Icons and ShortcutsAn inline command menu with icons on
- Command Popover Actions MenuA Quick Actions button that opens a
- Multiple Groups with Labels ComboboxA combobox with Frontend and Backend
- Command Popover with BadgesA Browse Components button that opens a