Components

Command

A searchable palette under a scrim

Import
import { Command } from "@nyte-ai/ui/command";

A dialog near the top of the window holding an inline Autocomplete. The dialog owns open state, the scrim, and focus; the autocomplete owns the input, the highlight, and arrow-key and Enter handling. Focus lands in the input when the palette opens, and Enter runs the highlighted row's onClick.

Usage

  • The palette does not filter. Render the rows that match the query from onValueChange, and pass their values to items in render order, so the highlight tracks the rows that exist.
  • Command.Empty shows its children while items is empty and announces the change. Keep it mounted and change its text for loading, failure, and no match.
  • Command.Popup names the dialog with its title, read by screen readers only. Name the palette after what it searches.
  • Rows keep the menu's three columns, leading, label, and meta, so labels align in every group.
  • Coming from shadcn's Command: CommandDialog is Command.Root plus Command.Popup, heading keeps its name, onSelect is onClick, and CommandShortcut is meta. value on the popup is the query, as in Base UI, not the highlighted row. Use onItemHighlighted for that.

Anatomy

<Command.Root>
  <Command.Trigger />
  <Command.Popup>
    <Command.Input />
    <Command.List>
      <Command.Empty />
      <Command.Group>
        <Command.Item />
      </Command.Group>
      <Command.Separator />
    </Command.List>
  </Command.Popup>
</Command.Root>

Examples

const [open, setOpen] = useState(false);
const [query, setQuery] = useState("");
const matches = commands.filter((command) =>
  command.label.toLowerCase().includes(query.toLowerCase()),
);

<Command.Root open={open} onOpenChange={setOpen}>
  <Command.Trigger render={<Button variant="outline">Search</Button>} />
  <Command.Popup
    title="Search commands"
    items={matches.map((command) => command.id)}
    value={query}
    onValueChange={setQuery}
  >
    <Command.Input aria-label="Search" placeholder="Search…" trailing={<Kbd keys={["⌘", "K"]} />} />
    <Command.List>
      <Command.Empty>No commands match "{query}"</Command.Empty>
      <Command.Group heading="Commands">
        {matches.map((command) => (
          <Command.Item
            key={command.id}
            value={command.id}
            leading={<Icon name={command.icon} size={16} />}
            meta={<Kbd keys={command.keys} plain />}
            onClick={() => {
              setOpen(false);
              command.run();
            }}
          >
            {command.label}
          </Command.Item>
        ))}
      </Command.Group>
    </Command.List>
  </Command.Popup>
</Command.Root>;

Props

PartRendersStyling
Command.RootNothingNone
Command.Trigger<button>None
Command.PopupA portal, the scrim, a viewport, a <div>, the list rootTranslucent panel near the top
Command.InputA <div> holding the search glyph and an <input>Full-width row under a hairline
Command.List<div role="listbox">Scrolls when rows overflow
Command.Group<div role="group"> with an optional headingSmall, secondary heading
Command.Separator<div role="separator">Hairline
Command.Item<div role="option">Three columns, highlighted on hover
Command.Empty<div role="status">Centered secondary text
Command.Close<button>None

Except Command.Root, each part takes xstyle, className, and style. className and style take plain values, not functions of state. See Theming.

The part tables below come from Base UI, MIT, © Material-UI SAS.

Root

Groups all parts of the dialog. Doesn't render its own HTML element.

Root Props:

PropTypeDefaultDescription
defaultOpenbooleanfalseWhether the dialog is initially open. To render a controlled dialog, use the open prop instead.
openboolean-Whether the dialog is currently open.
onOpenChange((open: boolean, eventDetails: Dialog.Root.ChangeEventDetails) => void)-Event handler called when the dialog is opened or closed.
actionsRefReact.RefObject<Dialog.Root.Actions | null>-A ref to imperative actions. unmount: Manually unmounts the dialog. Call this after any externally controlled closing animation finishes.close: Closes the dialog imperatively when called.
defaultTriggerIdstring | null-ID of the trigger that the dialog is associated with. This is useful in conjunction with the defaultOpen prop to create an initially open dialog.
disablePointerDismissalbooleanfalseWhether to prevent the dialog from closing on outside presses. For non-modal dialogs, this also prevents the dialog from closing when focus moves outside of it.
handleDialog.Handle<Payload>-A handle to associate the dialog with a trigger. If specified, allows external triggers to control the dialog's open state. Can be created with the Dialog.createHandle() method.
modalboolean | 'trap-focus'trueDetermines if the dialog enters a modal state when open. true: user interaction is limited to just the dialog: focus is trapped, document page scroll is locked, and pointer interactions on outside elements are disabled.false: user interaction with the rest of the document is allowed.'trap-focus': focus is trapped inside the dialog, but document page scroll is not locked and pointer interactions outside of it remain enabled. When modal is true or 'trap-focus', render <Dialog.Close> inside <Dialog.Popup> so touch screen readers can escape the popup.
onOpenChangeComplete((open: boolean) => void)-Event handler called after any animations complete when the dialog is opened or closed.
triggerIdstring | null-ID of the trigger that the dialog is associated with. This is useful in conjunction with the open prop to create a controlled dialog. There's no need to specify this prop when the dialog is uncontrolled (that is, when the open prop is not set).
childrenReact.ReactNode | PayloadChildRenderFunction<Payload>-The content of the dialog. This can be a regular React node or a render function that receives the payload of the active trigger.

Trigger

A button that opens the dialog. Renders a <button> element.

Trigger Props:

PropTypeDefaultDescription
handleDialog.Handle<Payload>-A handle to associate the trigger with a dialog. Can be created with the Dialog.createHandle() method.
nativeButtonbooleantrueWhether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).
payloadPayload-A payload to pass to the dialog when it is opened.
idstring-ID of the trigger. In addition to being forwarded to the rendered element, it is also used to specify the active trigger for the dialog in controlled mode (with the Dialog.Root triggerId prop).
classNamestring | ((state: Dialog.Trigger.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Dialog.Trigger.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Dialog.Trigger.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Trigger Data Attributes:

AttributeTypeDescription
data-popup-open-Present when the corresponding dialog is open.
data-disabled-Present when the trigger is disabled.

Renders the portal, scrim, viewport, popup, and a visually hidden title, then an always-open inline autocomplete root with autoHighlight="always" and keepHighlight. It takes the Base UI dialog popup props, including ref, and these.

PropTypeDefaultDescription
titlestring"Command palette"The dialog's accessible name.
descriptionstringThe dialog's accessible description.
tintTintScopes the panel to a hue. The scrim stays neutral.
itemsreadonly ItemValue[]Every row's value, in render order.
loopFocusbooleantrueWhether arrow keys wrap from the last row to the first.
valuestringThe controlled query.
defaultValuestringThe initial query when uncontrolled.
onValueChange(value, eventDetails) => voidFires as the query changes.
onItemHighlighted(value, eventDetails) => voidFires as the highlight moves.
itemToStringValue(value) => stringNames a non-string value for assistive tech.

A container for the dialog contents. Renders a <div> element.

Popup Props:

PropTypeDefaultDescription
initialFocusboolean | React.RefObject<HTMLElement | null> | ((openType: InteractionType) => boolean | void | HTMLElement | null)-Determines the element to focus when the dialog is opened. By default, focus moves to the first tabbable element inside the popup, except when the dialog is opened by touch — then the popup itself is focused to avoid opening the virtual keyboard. false: Do not move focus.true: Move focus based on the default behavior (first tabbable element or popup).RefObject: Move focus to the ref element.function: Called with the interaction type (mouse, touch, pen, or keyboard). Return an element to focus, true to use the default behavior, null to fall back to the default behavior, or false/undefined to do nothing.
finalFocusboolean | React.RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | void | HTMLElement | null)-Determines the element to focus when the dialog is closed. false: Do not move focus.true: Move focus based on the default behavior (trigger or previously focused element).RefObject: Move focus to the ref element.function: Called with the interaction type (mouse, touch, pen, or keyboard). Return an element to focus, true to use the default behavior, null to fall back to the default behavior, or false/undefined to do nothing.
classNamestring | ((state: Dialog.Popup.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Dialog.Popup.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Dialog.Popup.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Popup Data Attributes:

AttributeTypeDescription
data-open-Present when the dialog is open.
data-closed-Present when the dialog is closed.
data-nested-Present when the dialog is nested within another dialog.
data-nested-dialog-open-Present when the dialog has other open dialogs nested within it.
data-starting-style-Present when the dialog begins animating in.
data-ending-style-Present when the dialog is animating out.

Popup CSS Variables:

VariableTypeDescription
--nested-dialogsnumberIndicates how many dialogs are nested within.

Input

PropTypeDefaultDescription
trailingReactNodeRight of the field: a shortcut, a clear button.

A text input to search for items in the list. Renders an <input> element.

Input Props:

PropTypeDefaultDescription
disabledbooleanfalseWhether the component should ignore user interaction.
classNamestring | ((state: Autocomplete.Input.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Autocomplete.Input.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Autocomplete.Input.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Input Data Attributes:

AttributeTypeDescription
data-popup-open-Present when the corresponding popup is open.
data-popup-side'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start' | nullIndicates which side the corresponding popup is positioned relative to its anchor.
data-list-empty-Present when the corresponding items list is empty.
data-pressed-Present when the input is pressed.
data-disabled-Present when the component is disabled.
data-readonly-Present when the component is readonly.
data-required-Present when the component is required.
data-valid-Present when the component is in a valid state (when wrapped in Field.Root).
data-invalid-Present when the component is in an invalid state (when wrapped in Field.Root).
data-dirty-Present when the component's value has changed (when wrapped in Field.Root).
data-touched-Present when the component has been touched (when wrapped in Field.Root).
data-filled-Present when the component has a value (when wrapped in Field.Root).
data-focused-Present when the input is focused (when wrapped in Field.Root).

List

A list container for the items. Renders a <div> element.

List Props:

PropTypeDefaultDescription
childrenReact.ReactNode | ((item: any, index: number) => React.ReactNode)--
classNamestring | ((state: Autocomplete.List.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Autocomplete.List.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Autocomplete.List.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Group

PropTypeDefaultDescription
headingReactNodeLabels the group; the rows follow.

Groups related items with the corresponding label. Renders a <div> element.

Group Props:

PropTypeDefaultDescription
itemsany[]-Items to be rendered within this group. When provided, child Collection components will use these items.
classNamestring | ((state: Autocomplete.Group.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Autocomplete.Group.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Autocomplete.Group.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Group Data Attributes:

AttributeTypeDescription
data-popup-open-Present when the corresponding popup is open.
data-popup-side'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start' | nullIndicates which side the corresponding popup is positioned relative to its anchor.
data-list-empty-Present when the corresponding items list is empty.
data-pressed-Present when the input group is pressed.
data-disabled-Present when the component is disabled.
data-readonly-Present when the component is readonly.
data-valid-Present when the component is in a valid state (when wrapped in Field.Root).
data-invalid-Present when the component is in an invalid state (when wrapped in Field.Root).
data-dirty-Present when the component's value has changed (when wrapped in Field.Root).
data-touched-Present when the component has been touched (when wrapped in Field.Root).
data-filled-Present when the component has a value (when wrapped in Field.Root).
data-focused-Present when the component is focused (when wrapped in Field.Root).

Separator

A visual separator between items or groups. Renders a <div> element.

Separator Props:

PropTypeDefaultDescription
orientationOrientation'horizontal'The orientation of the separator.
classNamestring | ((state: Autocomplete.Separator.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Autocomplete.Separator.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Autocomplete.Separator.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Item

PropTypeDefaultDescription
valueItemValueIdentifies the row; it must appear in items.
leadingReactNodeThe glyph column.
metaReactNodeDisplay only. It binds no key.
childrenReactNodeThe label.

An individual item in the list. Renders a <div> element.

Item Props:

PropTypeDefaultDescription
valueanynullA unique value that identifies this item.
onClick((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void)-An optional click handler for the item when selected. It fires when clicking the item with the pointer, as well as when pressing Enter with the keyboard if the item is highlighted when the Input or List element has focus.
indexnumber-The index of the item in the list. Improves performance when specified by avoiding the need to calculate the index automatically from the DOM.
nativeButtonbooleanfalseWhether the component renders a native <button> element when replacing it via the render prop. Set to true if the rendered element is a native button.
disabledbooleanfalseWhether the component should ignore user interaction.
childrenReact.ReactNode--
classNamestring | ((state: Autocomplete.Item.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Autocomplete.Item.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Autocomplete.Item.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Item Data Attributes:

AttributeTypeDescription
data-highlighted-Present when the item is highlighted.
data-disabled-Present when the item is disabled.

Empty

Renders its children only when the list is empty. Requires the items prop on the root component. Announces changes politely to screen readers. This component's root element must remain mounted in the DOM to announce changes consistently across screen readers. Avoid hiding or removing the component itself with display: none, hidden, aria-hidden, or conditional rendering. Prefer updating or conditionally rendering its children instead. Renders a <div> element.

Empty Props:

PropTypeDefaultDescription
classNamestring | ((state: Autocomplete.Empty.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Autocomplete.Empty.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Autocomplete.Empty.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Close

A button that closes the dialog. Renders a <button> element.

Close Props:

PropTypeDefaultDescription
nativeButtonbooleantrueWhether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).
classNamestring | ((state: Dialog.Close.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Dialog.Close.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Dialog.Close.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Close Data Attributes:

AttributeTypeDescription
data-disabled-Present when the button is disabled.