Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Command examples · Popover

Command Popover with Badges for React

A Browse Components button that opens a command popover where each component carries a Stable or Beta badge.

Framework
UI library

Four components, each tagged Stable or Beta with a Badge at the end of its row. Use a badge when people should know an item's state before they pick it, and keep its text to a word. The Browse Components 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

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 is this menu anchored to the button?

The Browse Components 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".

How does Stable or Beta sit at the end of the row?

The name's span has flex-1, so it fills the row and pushes the Badge to the end. Button and Input read Stable with variant="secondary", and Table and DataGrid read Beta with variant="outline". The status and the variant sit in the data beside each name.

Which icon goes with each component?

FileText is Button, Code is Input, Database is Table, and Package is DataGrid. The icon is the first child of CommandItem and is hidden from screen readers, since the name says the same thing.

What appears when nothing matches the search?

CommandEmpty in the list says "No components 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 components..." until someone types. Command filters and ranks the items by their text on its own.