Skip to content
Focsd homeFocsd homeFocsd
Forms

Command palette

A searchable command palette, opened with a button or, if you opt in, ⌘/Ctrl + K.

  • Tag: focsd-command
  • Pattern: Dialog + combobox
  • Category: Overlays

Example

Open command palette New project Open project Invite member Toggle theme
HTML
<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>

API

Attributes

AttributePropertyTypeDefault
labellabelstring—
openopenbooleanfalse
shortcutshortcut'' | 'mod+k'—

Methods

MethodDescription
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).

PartDescription
activeAdded to the highlighted option.
controlThe control element.
dialogThe dialog element.
emptyThe message shown when no command matches.
groupThe group element.
group-labelThe group label element.
inputThe input element.
listboxThe listbox element.
optionThe option element.
option-labelAn option's label.
shortcutAn option's keyboard shortcut.
option-iconAn option's icon (decorative).

Accessibility

  • A modal <dialog> with a combobox that filters a listbox of commands, grouped with named role="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

KeyAction
⌘/Ctrl + KToggle (with shortcut="mod+k")
Arrow Up / DownMove through commands (wraps around)
Home / EndFirst / last command
EnterRun the command (fires focsd-select) and close
EscapeClose