Command palette
A searchable command palette, opened with a button or, if you opt in, ⌘/Ctrl + K.
Example
<focsd-button commandfor="cmd-demo" command="show-modal" >Open command palette</focsd-button><focsd-command id="cmd-demo"> <focsd-command-item value="new-project" group="Projects" shortcut="N" >New project</focsd-command-item > <focsd-command-item value="open-project" group="Projects" >Open project</focsd-command-item > <focsd-command-item value="invite" group="People">Invite member</focsd-command-item> <focsd-command-item value="theme" group="Settings">Toggle theme</focsd-command-item></focsd-command>Usage
Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.
<script type="module"> import '@focsd-dev/components/focsd-command.js';</script>
<focsd-command>…</focsd-command>import { Command } from '@focsd-dev/react';
export function Example() { return <Command>…</Command>;}<script setup>import '@focsd-dev/components/focsd-command.js';</script>
<template> <focsd-command>…</focsd-command></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-command.js';
// template<focsd-command>…</focsd-command><script> import '@focsd-dev/components/focsd-command.js';</script>
<focsd-command>…</focsd-command>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
label | label | string | — |
open | open | boolean | false |
shortcut | shortcut | '' | 'mod+k' | — |
Methods
| Method | Description |
|---|---|
show(opener) | Open the palette with an empty query; focus returns to opener (default: the focused element) on close. |
hide() | Close the palette. |
showModal(opener) | Same as show(), so <focsd-button commandfor="…" command="show-modal"> opens the palette. |
close() | Same as hide(), for the close command. |
CSS parts
Style the inside of the component with ::part(), for example focsd-command::part(active).
| Part | Description |
|---|---|
active | Added to the highlighted option. |
control | The control element. |
dialog | The dialog element. |
empty | The message shown when no command matches. |
group | The group element. |
group-label | The group label element. |
input | The input element. |
listbox | The listbox element. |
option | The option element. |
option-label | An option's label. |
shortcut | An option's keyboard shortcut. |
option-icon | An option's icon (decorative). |
Accessibility
- A modal
<dialog>with a combobox that filters a listbox of commands, grouped with namedrole="group"s. - Arrow order always matches the order on screen.
- Focus returns to the element that was focused before opening.
- The
shortcut="mod+k"attribute is opt-in, so it never clashes with page shortcuts by default.
Keyboard
| Key | Action |
|---|---|
| ⌘/Ctrl + K | Toggle (with shortcut="mod+k") |
| Arrow Up / Down | Move through commands (wraps around) |
| Home / End | First / last command |
| Enter | Run the command (fires focsd-select) and close |
| Escape | Close |
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.