Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Command examples · Dialog

Command Dialog with Separators for React

A Search Files button that opens a command dialog with recent files, folders and media split by separators.

Framework
UI library

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 CommandDialog over the page, and Escape closes it. In React, Base UI handles the keyboard navigation.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

How does this dialog open?

The Search Files 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.

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 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 "Search files..." until someone types. Command filters and ranks the items by their text on its own.