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.
No results found.
<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>No results found.
import * as React from "react";
import { Command } from "@/components/vin/command";
const Icon = ({ children }: { children: React.ReactNode }) => (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">{children}</svg>
);
export function CommandBasic() {
return (
<div style={{ width: "100%", maxWidth: 440 }}>
<Command
onSelect={(value) => console.log(value)}
groups={[
{
heading: "Suggestions",
items: [
{ value: "calendar", label: "Calendar", icon: <Icon><rect x="3" y="4.5" width="18" height="16.5" rx="2.5" /><path d="M3 9.5h18M8 2.5v4M16 2.5v4" /></Icon> },
{ value: "emoji", label: "Search emoji", keywords: "smiley face", icon: <Icon><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" /></Icon> },
{ value: "calculator", label: "Calculator", disabled: true, icon: <Icon><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" /></Icon> },
],
},
{
heading: "Settings",
items: [
{ value: "profile", label: "Profile", shortcut: "⌘P", icon: <Icon><circle cx="12" cy="8" r="4" /><path d="M4 21a8 8 0 0 1 16 0" /></Icon> },
{ value: "billing", label: "Billing", shortcut: "⌘B", keywords: "payment invoice plan", icon: <Icon><rect x="2.5" y="5" width="19" height="14" rx="2" /><path d="M2.5 10h19" /></Icon> },
{ value: "settings", label: "Settings", shortcut: "⌘S", keywords: "preferences", icon: <Icon><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" /></Icon> },
],
},
]}
/>
</div>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Command, { type CommandGroup } from "@/components/vin/command.vue";
const groups: CommandGroup[] = [
{
heading: "Suggestions",
items: [
{ value: "calendar", label: "Calendar" },
{ value: "emoji", label: "Search emoji", keywords: "smiley face" },
{ value: "calculator", label: "Calculator", disabled: true },
],
},
{
heading: "Settings",
items: [
{ value: "profile", label: "Profile", shortcut: "⌘P" },
{ value: "billing", label: "Billing", shortcut: "⌘B", keywords: "payment invoice plan" },
{ value: "settings", label: "Settings", shortcut: "⌘S", keywords: "preferences" },
],
},
];
const onSelect = (value: string) => console.log(value);
</script>
<template>
<div style="width: 100%; max-width: 440px">
<Command :groups="groups" @select="onSelect">
<template #icon="{ item }">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<template v-if="item.value === 'calendar'"><rect x="3" y="4.5" width="18" height="16.5" rx="2.5" /><path d="M3 9.5h18M8 2.5v4M16 2.5v4" /></template>
<template v-else-if="item.value === 'emoji'"><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" /></template>
<template v-else-if="item.value === 'calculator'"><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" /></template>
<template v-else-if="item.value === 'profile'"><circle cx="12" cy="8" r="4" /><path d="M4 21a8 8 0 0 1 16 0" /></template>
<template v-else-if="item.value === 'billing'"><rect x="2.5" y="5" width="19" height="14" rx="2" /><path d="M2.5 10h19" /></template>
<template v-else><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" /></template>
</svg>
</template>
</Command>
</div>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Command from "$lib/components/vin/command.svelte";
</script>
{#snippet 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>{/snippet}
{#snippet emoji()}<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>{/snippet}
{#snippet calculator()}<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>{/snippet}
{#snippet 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>{/snippet}
{#snippet billing()}<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>{/snippet}
{#snippet settings()}<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>{/snippet}
<div style="width: 100%; max-width: 440px">
<Command
onSelect={(value) => console.log(value)}
groups={[
{
heading: "Suggestions",
items: [
{ value: "calendar", label: "Calendar", icon: calendar },
{ value: "emoji", label: "Search emoji", keywords: "smiley face", icon: emoji },
{ value: "calculator", label: "Calculator", disabled: true, icon: calculator },
],
},
{
heading: "Settings",
items: [
{ value: "profile", label: "Profile", shortcut: "⌘P", icon: profile },
{ value: "billing", label: "Billing", shortcut: "⌘B", keywords: "payment invoice plan", icon: billing },
{ value: "settings", label: "Settings", shortcut: "⌘S", keywords: "preferences", icon: settings },
],
},
]}
/>
</div>⌘K palette
The button or ⌘K (Ctrl+K on Windows and Linux) opens it; Esc closes it.
<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>import * as React from "react";
import { CommandDialog } from "@/components/vin/command";
import { Button } from "@/components/vin/button";
import { Kbd, KbdGroup } from "@/components/vin/kbd";
const Icon = ({ children }: { children: React.ReactNode }) => (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">{children}</svg>
);
const page = <Icon><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" /></Icon>;
const sun = <Icon><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" /></Icon>;
export function CommandDialogExample() {
return (
<CommandDialog
title="Search docs"
footer
trigger={<Button variant="outline">Search docs… <KbdGroup><Kbd>⌘</Kbd><Kbd>K</Kbd></KbdGroup></Button>}
onSelect={(value) => console.log(value)}
groups={[
{
heading: "Pages",
items: [
{ value: "installation", label: "Installation", href: "#installation", icon: page },
{ value: "theming", label: "Theming", href: "#theming", keywords: "colour color accent", icon: <Icon><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" /></Icon> },
{ value: "cli", label: "CLI", href: "#cli", keywords: "command line npx", icon: page },
],
},
{
heading: "Theme",
items: [
{ value: "light", label: "Light mode", icon: sun },
{ value: "dark", label: "Dark mode", keywords: "night", icon: sun },
],
},
]}
/>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import { CommandDialog, type CommandGroup } from "@/components/vin/command.vue";
import Button from "@/components/vin/button.vue";
import Kbd, { KbdGroup } from "@/components/vin/kbd.vue";
const groups: CommandGroup[] = [
{
heading: "Pages",
items: [
{ value: "installation", label: "Installation", href: "#installation" },
{ value: "theming", label: "Theming", href: "#theming", keywords: "colour color accent" },
{ value: "cli", label: "CLI", href: "#cli", keywords: "command line npx" },
],
},
{
heading: "Theme",
items: [
{ value: "light", label: "Light mode" },
{ value: "dark", label: "Dark mode", keywords: "night" },
],
},
];
const onSelect = (value: string) => console.log(value);
</script>
<template>
<CommandDialog title="Search docs" footer :groups="groups" @select="onSelect">
<template #trigger>
<Button variant="outline">Search docs… <KbdGroup><Kbd>⌘</Kbd><Kbd>K</Kbd></KbdGroup></Button>
</template>
<template #icon="{ item }">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<template v-if="item.value === 'theming'"><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" /></template>
<template v-else-if="item.href"><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" /></template>
<template v-else><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" /></template>
</svg>
</template>
</CommandDialog>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import CommandDialog from "$lib/components/vin/command-dialog.svelte";
import Button from "$lib/components/vin/button.svelte";
import Kbd from "$lib/components/vin/kbd.svelte";
import KbdGroup from "$lib/components/vin/kbd-group.svelte";
</script>
{#snippet page()}<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>{/snippet}
{#snippet 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>{/snippet}
{#snippet sun()}<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>{/snippet}
<CommandDialog
title="Search docs"
footer
onSelect={(value) => console.log(value)}
groups={[
{
heading: "Pages",
items: [
{ value: "installation", label: "Installation", href: "#installation", icon: page },
{ value: "theming", label: "Theming", href: "#theming", keywords: "colour color accent", icon: theming },
{ value: "cli", label: "CLI", href: "#cli", keywords: "command line npx", icon: page },
],
},
{
heading: "Theme",
items: [
{ value: "light", label: "Light mode", icon: sun },
{ value: "dark", label: "Dark mode", keywords: "night", icon: sun },
],
},
]}
>
{#snippet trigger(props)}<Button variant="outline" {...props}>Search docs… <KbdGroup><Kbd>⌘</Kbd><Kbd>K</Kbd></KbdGroup></Button>{/snippet}
</CommandDialog>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:
npx @vinish/ui add commandimport { Command, CommandDialog } from "@/components/vin/command";import Command, { CommandDialog } from "@/components/vin/command.vue";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.
| Prop | Values | Default | In HTML |
|---|---|---|---|
groupsThe 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] |
onSelectCalled when a command is chosen (Enter or click). | (value: string) => void | — | a vin-command event with detail.value; data-href goes to a page |
placeholder | string | Type a command or search… | placeholder on the input |
emptyText | ReactNode | No results found. | <p class="vin-command__empty" role="status"> |
labelName for the search box and the list. | string | Commands | — |
footerShow key hints under the list. | boolean | false | .vin-command__footer |
CommandDialog: trigger / open / onOpenChange / shortcutThe palette in a modal dialog, opened by the trigger or ⌘K / Ctrl+K. | ReactElement / boolean / (open) => void / string | shortcut "k" | dialog.vin-dialog.vin-command-dialog[data-vin-shortcut="k"] |
Parts
| React, Vue, Svelte | HTML 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.
Customize
Saved in this browser. Style and accent are in the header.