Mushilu-San UI

Search components

PlaygroundStorybookGitHub
Overlays

Command

A searchable list of commands and pages, the building block for a command palette.

Selector: mui-command

Import
import { Command, CommandInput, CommandList, CommandGroup, CommandItem, CommandEmpty, CommandSeparator } from '@mushilu-san/ui/overlays';
PreviewCode

Loading example…

Overview

Command holds a search input and a role="listbox" of groups and items. search is a two-way model with the query. Each mui-command-item has a value, and choosing one emits itemActivated.

Use CommandEmpty for the message shown when nothing matches. shortcut shows the keys for an item.

When to use

  • A command palette that opens with Cmd+K and lists actions and pages.
  • A large set of commands that users search by name.

When not to use

  • Picking a value for a form field. Use a combobox. Use Combobox instead.
  • A short menu of actions for one item. Use a dropdown menu. Use Dropdown menu instead.

Guidelines

Do

  • Group items by type, such as "Pages" and "Actions".
  • Show a shortcut next to commands that have one.

Don't

  • Do not put every setting in the palette. Keep the common ones.

Accessibility

Roles and attributes

ElementRoleNotes
listlistboxNamed "Results" by default. Options are role="option" with aria-selected on the highlighted one.
groupgroupNamed by label.
empty message—aria-live="polite", so it is announced when no item matches.

Keyboard

KeysAction
TypeFilters the items.
ArrowDownArrowUpMove the highlight through the items.
EnterRuns the highlighted item.
  • Put focus in the search input when the palette opens, so typing works at once.

API

Command

Selector: mui-command

NameTypeDefaultDescription
placeholderstring'Search…' Placeholder for the built-in CommandInput (if used without a custom input).
NameTypeDefaultDescription
searchstring'' The current search string — two-way bindable.
NameTypeDescription
itemActivated{ value: string; label: string; } Emits the `value` and `label` of the item the user runs.

CSS parts

  • ::part(container)
  • ::part(root)

CommandInput

Selector: mui-command-input

NameTypeDefaultDescription
placeholderstring'Search…' Hint text shown while the search is empty. Default `Search…`.

CSS parts

  • ::part(input)
  • ::part(input-root)
  • ::part(input-wrapper)

CommandList

Selector: mui-command-list

NameTypeDefaultDescription
labelstring'Results' Accessible name of the listbox (#726).

CSS parts

  • ::part(list)

CommandGroup

Selector: mui-command-group

NameTypeDefaultDescription
labelstring | undefined— Heading for the group. Also its accessible name.

CSS parts

  • ::part(group)
  • ::part(group-label)

CommandItem

Selector: mui-command-item

NameTypeDefaultDescription
valuerequiredstring— The searchable value for this item. Filters against ctx.search().
disabledbooleanfalse Disables the item. It cannot be highlighted or run. Accepts attribute presence, e.g. <… disabled>.
selectedbooleanfalse Marks the item as highlighted. Set by the keyboard handling. Accepts attribute presence, e.g. <… selected>.
shortcutstring | undefined— Keyboard shortcut shown on the right, for display only.
NameTypeDescription
activatedstring Emits the item's `value` when it is run.

CSS parts

  • ::part(item)
  • ::part(item-root)

CommandEmpty

Selector: mui-command-empty

CSS parts

  • ::part(empty)

CommandSeparator

Selector: mui-command-separator

CSS parts

  • ::part(separator)

Tokens

  • --mui-color-surface-raised
  • --mui-color-border
  • --mui-color-primary-subtle
  • --mui-shadow-4
  • --mui-color-focus-ring