ZUI

Search documentation

Find a page or a heading.

Command menu

A command palette for jumping to a target: a CommandDialog holding a Command that reports the chosen item's value and closes.

Installation

bash

The CLI writes components/navigation/command-menu.tsx and installs Command with the items it needs.

Usage

tsx
tsx

Compose CommandInput, CommandList, CommandEmpty and the items as children, and open the menu from a control of your own, such as a button. The dialog draws in a portal, so the app needs a PortalHost, as for Dialog.

Composition

text

API reference

CommandMenu

Takes every prop of CommandDialog except onOpenChange, which is redefined, plus:

It defaults CommandDialog's title to 'Command menu' and description to 'Search for a target to jump to.', which a screen reader reads though they are not drawn. onOpenChange is called with false after an item is chosen.

CommandMenuItem

Takes every prop of CommandItem except value, which is required here:

Choosing it runs the item's own onSelect if given, then reports value through the menu's onValueChange and closes the dialog. The typed text is matched against value.

Differences from the web

  • The web's useCommandShortcut hook, which opens the menu on Cmd+K or Ctrl+K, is not ported, since a phone has no such key; open the menu from a control.
  • Each item's label is a Text child, where the web's item takes the string itself.
  • The web's data-slot attributes are not set; a View takes no data attributes.