Skip to content

Command

A search box that filters a list of commands and pages: inline, or as a ⌘K palette. Same markup and props in every style: switch the style in the header to see it change.

Inline

Type to filter; ↓ ↑ to move and Enter to run. Words in data-keywords match too. In HTML, add data-vin-command and include vinui.js once.

Calendar
Search emoji
Calculator
Profile
Billing
Settings
command-basic.html
<div style="width: 100%; max-width: 440px">
  <div class="vin-command" data-vin-command>
    <div class="vin-command__search">
      <svg class="vin-command__icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg>
      <input class="vin-command__input" type="text" role="combobox" aria-expanded="true" aria-controls="cmd-list" aria-autocomplete="list" aria-label="Search commands" placeholder="Type a command or search…" autocomplete="off" spellcheck="false">
    </div>
    <div class="vin-command__list" id="cmd-list" role="listbox" aria-label="Commands">
      <div class="vin-command__group" role="group" aria-labelledby="cmd-g0">
        <div class="vin-command__label" id="cmd-g0" role="presentation">Suggestions</div>
        <div class="vin-command__item" role="option" id="cmd-0" aria-selected="false" data-value="calendar"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="4.5" width="18" height="16.5" rx="2.5"/><path d="M3 9.5h18M8 2.5v4M16 2.5v4"/></svg>Calendar</div>
        <div class="vin-command__item" role="option" id="cmd-1" aria-selected="false" data-value="emoji" data-keywords="smiley face"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M8 14s1.5 2 4 2 4-2 4-2"/><path d="M9 9h.01M15 9h.01"/></svg>Search emoji</div>
        <div class="vin-command__item" role="option" id="cmd-2" aria-selected="false" data-value="calculator" aria-disabled="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="5" y="2.5" width="14" height="19" rx="2"/><path d="M8 6.5h8M8 11h.01M12 11h.01M16 11h.01M8 15h.01M12 15h.01M16 15h.01M8 18.5h8"/></svg>Calculator</div>
      </div>
      <div class="vin-command__separator" role="presentation"></div>
      <div class="vin-command__group" role="group" aria-labelledby="cmd-g1">
        <div class="vin-command__label" id="cmd-g1" role="presentation">Settings</div>
        <div class="vin-command__item" role="option" id="cmd-3" aria-selected="false" data-value="profile"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="8" r="4"/><path d="M4 21a8 8 0 0 1 16 0"/></svg>Profile<span class="vin-command__shortcut" aria-hidden="true">⌘P</span></div>
        <div class="vin-command__item" role="option" id="cmd-4" aria-selected="false" data-value="billing" data-keywords="payment invoice plan"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="2.5" y="5" width="19" height="14" rx="2"/><path d="M2.5 10h19"/></svg>Billing<span class="vin-command__shortcut" aria-hidden="true">⌘B</span></div>
        <div class="vin-command__item" role="option" id="cmd-5" aria-selected="false" data-value="settings" data-keywords="preferences"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.7 1.7 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.8-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1a1.7 1.7 0 0 0-1.1-1.5 1.7 1.7 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.7 1.7 0 0 0 .3-1.8 1.7 1.7 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1a1.7 1.7 0 0 0 1.5-1.1 1.7 1.7 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.7 1.7 0 0 0 1.8.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.8V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1Z"/></svg>Settings<span class="vin-command__shortcut" aria-hidden="true">⌘S</span></div>
      </div>
    </div>
    <p class="vin-command__empty" role="status" hidden>No results found.</p>
  </div>
</div>

⌘K palette

The button or ⌘K (Ctrl+K on Windows and Linux) opens it; Esc closes it.

Installation
Theming
CLI
Light mode
Dark mode
command-dialog.html
<button type="button" class="vin-btn vin-btn--outline" commandfor="cmd-palette" command="show-modal" aria-keyshortcuts="Meta+K Control+K">Search docs… <kbd class="vin-kbd-group"><kbd class="vin-kbd">⌘</kbd><kbd class="vin-kbd">K</kbd></kbd></button>
<dialog class="vin-dialog vin-command-dialog" id="cmd-palette" aria-label="Search docs" closedby="any" data-vin-shortcut="k">
  <div class="vin-command" data-vin-command>
    <div class="vin-command__search">
      <svg class="vin-command__icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg>
      <input class="vin-command__input" type="text" role="combobox" aria-expanded="true" aria-controls="cmdp-list" aria-autocomplete="list" aria-label="Search commands" placeholder="Type a command or search…" autocomplete="off" spellcheck="false">
    </div>
    <div class="vin-command__list" id="cmdp-list" role="listbox" aria-label="Commands">
      <div class="vin-command__group" role="group" aria-labelledby="cmdp-g0">
        <div class="vin-command__label" id="cmdp-g0" role="presentation">Pages</div>
        <div class="vin-command__item" role="option" id="cmdp-0" aria-selected="false" data-value="installation" data-href="#installation"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 2.5H6a2 2 0 0 0-2 2v15a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-11Z"/><path d="M14 2.5v6h6"/></svg>Installation</div>
        <div class="vin-command__item" role="option" id="cmdp-1" aria-selected="false" data-value="theming" data-keywords="colour color accent" data-href="#theming"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="13.5" cy="6.5" r="1"/><circle cx="17.5" cy="10.5" r="1"/><circle cx="8.5" cy="7.5" r="1"/><circle cx="6.5" cy="12.5" r="1"/><path d="M12 2a10 10 0 0 0 0 20c.9 0 1.7-.8 1.7-1.7 0-.4-.2-.8-.4-1.1-.3-.3-.4-.7-.4-1.1 0-.9.8-1.7 1.7-1.7h2A5.6 5.6 0 0 0 22 11c0-5-4.5-9-10-9Z"/></svg>Theming</div>
        <div class="vin-command__item" role="option" id="cmdp-2" aria-selected="false" data-value="cli" data-keywords="command line npx" data-href="#cli"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 2.5H6a2 2 0 0 0-2 2v15a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-11Z"/><path d="M14 2.5v6h6"/></svg>CLI</div>
      </div>
      <div class="vin-command__separator" role="presentation"></div>
      <div class="vin-command__group" role="group" aria-labelledby="cmdp-g1">
        <div class="vin-command__label" id="cmdp-g1" role="presentation">Theme</div>
        <div class="vin-command__item" role="option" id="cmdp-3" aria-selected="false" data-value="light"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/></svg>Light mode</div>
        <div class="vin-command__item" role="option" id="cmdp-4" aria-selected="false" data-value="dark" data-keywords="night"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/></svg>Dark mode</div>
      </div>
    </div>
    <p class="vin-command__empty" role="status" hidden>No results found.</p>
    <div class="vin-command__footer" aria-hidden="true"><span><kbd class="vin-kbd">↑</kbd><kbd class="vin-kbd">↓</kbd> to move</span><span><kbd class="vin-kbd">↵</kbd> to open</span><span><kbd class="vin-kbd">Esc</kbd> to close</span></div>
  </div>
</dialog>

Installation

React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:

Terminal
npx @vinish/ui add command
React
import { Command, CommandDialog } from "@/components/vin/command";
Vue
import Command, { CommandDialog } from "@/components/vin/command.vue";
Svelte
import Command from "$lib/components/vin/command.svelte";
import CommandDialog from "$lib/components/vin/command-dialog.svelte";

The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.

Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.

API

From spec/command.json, which every framework version is tested against.

PropValuesDefaultIn HTML
groups
The commands, in groups.
{ heading?, items: { value, label, icon?, shortcut?, keywords?, href?, disabled? }[] }[]—.vin-command__group[role=group] > .vin-command__label + .vin-command__item[role=option][data-value]
onSelect
Called when a command is chosen (Enter or click).
(value: string) => void—a vin-command event with detail.value; data-href goes to a page
placeholderstringType a command or search…placeholder on the input
emptyTextReactNodeNo results found.<p class="vin-command__empty" role="status">
label
Name for the search box and the list.
stringCommands—
footer
Show key hints under the list.
booleanfalse.vin-command__footer
CommandDialog: trigger / open / onOpenChange / shortcut
The palette in a modal dialog, opened by the trigger or ⌘K / Ctrl+K.
ReactElement / boolean / (open) => void / stringshortcut "k"dialog.vin-dialog.vin-command-dialog[data-vin-shortcut="k"]

Parts

React, Vue, SvelteHTML classes
<Command><CommandDialog>.vin-command.vin-command__search.vin-command__icon.vin-command__input.vin-command__list.vin-command__group.vin-command__label.vin-command__item.vin-command__shortcut.vin-command__separator.vin-command__empty.vin-command__footer.vin-command-dialog

Accessibility

  • The search box is a combobox that controls a listbox; focus stays in it and aria-activedescendant points at the highlighted command.
  • Commands are role="option", grouped under labelled role="group" headings; groups with no matches disappear.
  • Keys: ↓ ↑ to move (they wrap), Ctrl+Home and Ctrl+End for the first and last, Enter to run, Esc to close the palette.
  • "No results found" is a status message, so screen readers announce it.
  • Shortcuts are shown for sighted users and hidden from screen readers, which read the command's name.