Skip to content

Actions & Overlays

Command Palette

A filterable list of commands with keyboard navigation.

stableEnhancer: enhanceCommandBuilt on <input> + listboxhydrateless/command-palette.css

A filterable list of commands with keyboard navigation, group hiding, and an empty state. Render it inline, or drop it inside a <dialog> and open it with a hotkey. Without JavaScript the full list simply renders; the root is marked data-hl-ready once filtering is live. The filter query is the component's value.

Command palette

Type to filter, navigate with Up/Down (and PageUp/PageDown in steps of ten), and run with Enter. Esc clears a non-empty query first, then closes the hosting <dialog>.

Live
Actions
New File
Open
Navigation
Go to Settings
Open Docs

JavaScript

This component ships an optional enhancer. With auto-init it loads automatically; to wire it yourself, import it directly:

import { enhanceCommand } from '@hydrateless/enhancers/command';

const handle = enhanceCommand(document);
// handle.api  -> imperative controls
// handle.destroy()  -> tear everything down

Props

The framework bindings expose these props (and forward the rest to the root element).

PropTypeDefaultDescription
querystringNot setControlled filter query; pair with `onQueryChange` (Vue: `v-model:query`, Svelte: `bind:query`).
defaultQuerystring''Uncontrolled initial query.
onQueryChange(query: string) => voidNot setCalled with the filter query after every change.
onCommand(value: string, item: HTMLElement) => voidNot setCalled when a command runs (Vue: the `command` emit).
hotkeystringNot setKey that, with Cmd/Ctrl, opens the hosting `<dialog>`, e.g. `"k"`; rendered as `data-hl-hotkey`.
CommandItem.value*stringNot setValue reported by `onCommand`; rendered as `data-hl-value`.
CommandGroup.labelstringNot setHeading shown above the group. In Vue it is a prop or the `label` slot; in Svelte it is the `label` snippet.
CommandItem.keywordsstringNot setExtra terms the filter matches against, rendered as `data-hl-keywords`.

Events and callbacks

Event / CallbackPayloadDescription
hl:command{ value: string, item: HTMLElement }Cancelable CustomEvent when a command runs; `preventDefault()` to handle navigation yourself.
hl:change{ value: string }Fires when the filter query changes (also the `onValueChange` enhancer callback).
hl:open-change{ open: boolean }Fires when the hosting `<dialog>` opens or closes (also the `onOpenChange` enhancer callback). The enhancer API exposes `open`/`setOpen` for it.

CSS variables

Override these on any ancestor to theme the component. See the theme studio to preview changes live.

CSS variableUsed for
--hl-overlayPalette background.
--hl-borderPalette border.
--hl-primary-subtleActive item highlight.
--hl-focus-ringFocus ring on the input.

Accessibility

  • The input is role="combobox" controlling the role="listbox", tracked with aria-activedescendant.
  • Filtering matches visible text plus any data-hl-keywords; groups with no visible options are hidden.
  • Esc clears the query before it closes the dialog, so a mistyped search never dismisses the palette by surprise.

Released under the MIT License.