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
Command palette
A modal search over commands and items. Type to filter, arrows to move, Enter to choose, Escape to close. Start with > for commands only or @ for environments.
Try it
Chosen: nothing yet
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
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
open | open | boolean | false | Whether the palette is showing. |
items | items | CommandPaletteItem[] | [] | Everything the palette can find, in the order sections and rows are listed. |
placeholder | placeholder | string | "" | The field's placeholder. Unset: "Search or run a command…", translated. |
label | label | string | "" | The palette's accessible name. Unset: "Command palette", translated. |
prefixes | prefixes | Record<string, string> | {} | Prefixes that limit the list to one section, e.g. { ">": "Commands", "@": "Environments" }. |
preview | property only | (item: CommandPaletteItem) => unknown | undefined | none | Renders 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. |
hints | hints | CommandPaletteHint[] | [] | Extra key hints after the built-in ones in the footer. |
Events
| Event | Description |
|---|---|
close | The palette closed by itself (Escape, a click outside, after select). |
select | An item was chosen. detail: { item, query }. The palette closes after it. |
tab | Tab was pressed. detail: { query }. Cancelable; the palette stays open either way. |
CSS parts
| Part | Description |
|---|---|
dialog | The native <dialog> panel. |
input | The search field. |
listbox | The list of results. |
option | Each result row. |
footer | The key hints. |
preview | The preview pane beside the list. |
CSS custom properties
| Property | Description |
|---|---|
--lit-material-command-palette-width | The panel's width (default min(640px, 100vw - 32px)). |
--lit-material-command-palette-max-height | The list's height limit (default min(60vh, 420px)). |
--lit-material-command-palette-top | Distance from the top of the window (default 12vh). |
--lit-material-command-palette-preview-width | The panel's width while a preview shows (default min(960px, 100vw - 32px)). |