Command Palette

Command palette web component: a modal ⌘K search over commands and items with fuzzy matching, sections, prefixes and full keyboard access.

  • 5.7 KB gzipped
  • @lit-material/command-palette 1.8.0
  • Renders on the server

Example

Install

npm install @lit-material/command-palette @lit-material/tokens
import "@lit-material/command-palette";

Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide

API

<lit-material-command-palette>

A modal command palette: one search field over commands and items, fuzzy matched, grouped by section, fully usable from the keyboard. Open it from your own shortcut (⌘K, Ctrl+K…) with show() or open — the palette binds no global keys.

Properties

PropertyAttributeTypeDefaultDescription
openopenbooleanfalseWhether the palette is showing.
itemsitemsCommandPaletteItem[][]Everything the palette can find, in the order sections and rows are listed.
placeholderplaceholderstring""The field's placeholder. Unset: "Search or run a command…", translated.
labellabelstring""The palette's accessible name. Unset: "Command palette", translated.
prefixesprefixesRecord<string, string>{}Prefixes that limit the list to one section, e.g. { ">": "Commands", "@": "Environments" }.
previewproperty only(item: CommandPaletteItem) => unknown | undefinednoneRenders a preview of the active item in a pane beside the list (anything Lit can render: a template, a string, a node). Return nothing, null or undefined for no preview. Unset: no pane. The pane hides below 720px of width.
hintshintsCommandPaletteHint[][]Extra key hints after the built-in ones in the footer.

Events

EventDescription
closeThe palette closed by itself (Escape, a click outside, after select).
selectAn item was chosen. detail: { item, query }. The palette closes after it.
tabTab was pressed. detail: { query }. Cancelable; the palette stays open either way.

CSS parts

PartDescription
dialogThe native <dialog> panel.
inputThe search field.
listboxThe list of results.
optionEach result row.
footerThe key hints.
previewThe preview pane beside the list.

CSS custom properties

PropertyDescription
--lit-material-command-palette-widthThe panel's width (default min(640px, 100vw - 32px)).
--lit-material-command-palette-max-heightThe list's height limit (default min(60vh, 420px)).
--lit-material-command-palette-topDistance from the top of the window (default 12vh).
--lit-material-command-palette-preview-widthThe panel's width while a preview shows (default min(960px, 100vw - 32px)).

Source on GitHub npm