Command

new

A filterable list of commands, inline or in a dialog, built on Reka UI's Listbox.

Demo

Open Props in the corner of the example to try size and disabled.

size takes Menu's scale: item heights from 28px at xs to 48px at xl, with the search row, icons and type to match.

Installation

Usage

<script setup lang="ts">
import {
  Command,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandLabel,
  CommandList,
} from '@/components/ui/command'
</script>

<template>
  <Command>
    <CommandInput placeholder="Type a command or search..." />
    <CommandList>
      <CommandEmpty>No results found.</CommandEmpty>
      <CommandGroup>
        <CommandLabel>Suggestions</CommandLabel>
        <CommandItem value="calendar" @select="openCalendar">Calendar</CommandItem>
      </CommandGroup>
    </CommandList>
  </Command>
</template>

Command is a port of shadcn's command menu onto Reka UI's Listbox. Typing in CommandInput filters the items by their text, ignoring case and accents. A group with no match hides, separators hide while there is a search, and CommandEmpty shows when nothing matches. The arrow keys move the highlight from the search field, and Enter or a click fires the item's select and clears the search.

Command has no surface of its own beyond the popover colour and a radius, so give it a border or a shadow where it stands on the page. Items, labels, separators and shortcuts share Menu's styles.

Examples

Dialog

CommandDialog puts the command in a dialog, the usual command palette. It opens with v-model:open; here ⌘J or Ctrl+J also toggles it, since ⌘K already opens this site's search. The search takes focus when it opens. title and description name the dialog for screen readers only, and show-close-button adds the dialog's close button.

Dialog
or press ⌘J

API Reference

Every part accepts class, merged over its base classes.

CommandGroup, CommandLabel, CommandList, CommandEmpty, CommandSeparator, CommandShortcut

CommandGroup holds a CommandLabel and items, CommandList scrolls them at up to 300px, and CommandShortcut shows a key combination at the end of an item without registering it.

Data attributes

data-slotAttributesDescription
commanddata-sizeThe root, Reka's Listbox root.
command-input-wrapperThe search row with its icon.
command-inputThe search field.
command-listThe scrolling list, a role="listbox".
command-emptyShown while a search matches nothing.
command-grouphiddenA role="group", hidden while none of its items matches.
command-labelThe group's name.
command-itemdata-highlighted, data-disabled, data-stateOne command, a role="option".
command-separatorA line between groups, removed while searching.
command-shortcutA key combination at the end of an item.

Keyboard

KeyAction
ArrowDown / ArrowUpMoves the highlight to the next or previous enabled item.
Home / EndMoves the highlight to the first or last item.
EnterSelects the highlighted item and clears the search.
EscapeCloses a CommandDialog.

Changelog

  1. registry 0.15.0

    d09f26a — Pressable parts ripple on their own: Button, Toggle, ToggleGroupItem, Item as a link or a button, the calendar days, tabs, accordion, menubar and navigation menu triggers, the items of Menu, Menubar, Select, Combobox, Command, DrawerMenu, Listbox and Tree, and the clear buttons of TagsInput and Combobox. Each imports the directive from @/lib/ripple, so add brings the ripple item along and nothing needs registering. On menu, listbox and tree rows the wave replaces the pressed layer, as state-layer already did. Bind v-ripple="false" on a Button to turn one off, or set --kappa-ripple: none on :root to turn them all off.

  2. registry 0.14.0

    ef1938f — CommandList takes no room when it has nothing to show: with every item filtered out and no CommandEmpty, or with no items at all, it collapses, padding included. The line between the input and the results now belongs to the list, so it goes with it, and an input with nothing under it no longer ends in a stray border.

  3. registry 0.12.0

    c79028b — The control scale is now a set of tokens: --control-height-*, --control-padding-*, --control-icon-* and --control-gap-* for xs to xl, added to :root by the tokens item. Button, Input, InputFloating, Select, Combobox, InputNumber, TagsInput, PinInput, InputTime, InputGroup, Menu, Tabs, ColorPicker and Pagination read them, so overriding one on :root resizes every control of that size.

    Some sizes that strayed from the scale now follow it. Button icons are 20px at lg and xl instead of 16px, and so are the icons of Toggle, ToggleGroup, Toolbar and Pagination at those sizes. The gap between an icon and its label is 6, 8, 8, 10 and 12px from xs to xl, about half the icon, everywhere that has one: Button and the components built on it (where it was 4, 6, 8, 8 and 8px), Menu items and the Select, Combobox and Command lists (8, 10, 12, 12 and 12px), and Tabs triggers (6, 8, 8, 8 and 10px). Inset and checkbox or radio items move their labels with it, so they stay in line with items that have an icon. Everything else keeps its size.

  4. registry 0.11.0

    44a7ce2 — Command and CommandDialog take ignore-filter, which turns the built-in filter off for items you filter yourself: every item, group and separator stays visible and CommandEmpty never shows. CommandInput binds the search with v-model, and hears when selecting an item clears it. Items mounted after a search was set are filtered too.

  5. registry 0.10.0

    8f31bd2 — New Command: a filterable list of commands over Reka UI's Listbox, ported from shadcn-vue, in Menu's five sizes: CommandInput, CommandList, CommandEmpty, CommandGroup, CommandLabel, CommandItem, CommandSeparator, CommandShortcut and CommandDialog.