Skip to main content
Selecting a command item often should reveal a deeper set of related items — for example, selecting “Change theme…” should show “Dark” and “Light” options. cmdk implements this with a pages pattern: a plain array of strings that acts as a navigation stack.

The pages pattern

Track which page you’re on with useState. Render different items depending on the active page. Push to the stack when an item is selected; pop from the stack when Escape or Backspace is pressed:
Reset the search value when navigating to a new page so the new set of items is not pre-filtered by whatever the user typed previously.
The Vercel example shows the active page stack as badges rendered above the input — a useful affordance so users know where they are:

Show sub-items when searching

Sometimes you want sub-items to only appear when the user is actively searching — they are hidden at rest but surface during a query. Use useCommandState to read the current search string and conditionally render:
When the search input is empty, SubItem returns null and the sub-items are not in the DOM. As soon as the user types, they appear and are scored alongside all other items.
The SubItem pattern is great for surfacing deeply nested actions (e.g., “Open project settings > Billing”) without cluttering the default view.