overlayshwc
z-cmdCommand
Lazy-mounted modal command palette with live multi-token search, grouped actions, descriptions, and keycap hints.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
placeholder | string | '' | Overrides the search field placeholder from i18n. |
shortcut | string | '' | Global keyboard shortcut that toggles the palette, e.g. mod+k or /. Tokens: mod — ⌘ on macOS/iOS, Ctrl on Windows/Linux. ctrl (control) — Ctrl modifier. meta (cmd, command) — ⌘ / Windows key modifier. alt (option) — Alt / Option modifier. shift — Shift modifier. |
prevent-close | boolean | false | Keeps the palette open after an item is selected. |
no-footer | boolean | false | Hides the keyboard-hint and close bar. |
icon | string | '' | Icon key that replaces the default search icon. |
Inherited from DialogMixin
| Attribute | Type | Default | Description |
|---|---|---|---|
open | boolean · reflects | false | Opens the dialog on first render and stays in sync with show() and hide(). |
center | boolean | false | Vertically centers the panel within the overlay. |
container | boolean | false | Adds z-modal-container to the overlay for a contained presentation. |
full | boolean | false | Adds z-modal-full to the overlay for a full-screen presentation. |
stack | boolean | false | Keeps other open dialogs open; without it, showing this dialog hides them. Stacked overlays receive increasing z-index. |
inline | boolean | false | Keeps the component in its original DOM position instead of teleporting it to document.body. |
no-bg-close | boolean | false | Disables closing when the overlay background is clicked. |
no-esc-close | boolean | false | Disables closing with the Esc key. |
unmount | boolean | false | Removes the rendered DOM after the close transition; the next show mounts it again. |
dialog-role | 'dialog' | 'alertdialog' | 'dialog' | ARIA role of the panel: dialog or alertdialog. |
aria-label | string | '' | Accessible name for the panel when no aria-labelledby is set. |
aria-labelledby | string | '' | Id of the element that names the panel; takes precedence over aria-label. |
Inherited from Hwc
| Attribute | Type | Default | Description |
|---|---|---|---|
i18n | string | '' | Per-instance text overrides as key: text pairs, merged over the global z-i18n script and the built-in defaults. |
floating | string | '' | Floating UI placement options (for example offset and shiftPadding) parsed as key: value pairs. |
force-prevent-rerender | boolean | false | Skips re-rendering after the first render; an existing data-host-inner child is adopted as the rendered DOM. |
template | string | '' | Selector or id of an external element or <template> whose inner content is cloned in place of an inline template[data-fn="template"] child. |
Inherited from Base
| Attribute | Type | Default | Description |
|---|---|---|---|
cls | string | '' | Adds classes to named parts as key: classes pairs; a plain string targets the default part. |
stl | string | '' | Adds inline styles to named parts as key: styles pairs; a plain string targets the default part. |
Custom Styling (cls / stl)
Default cls target:dialog · defaultstl target:dialog
| Key | Default class | cls | stl | Description |
|---|---|---|---|---|
dialog | z-modal-dialog z-cmd | yes | yes | Dialog container; the default cls and stl target. |
divider | z-hr | yes | yes | Horizontal rule between the search field and the results. |
empty | z-cmd-empty | yes | yes | Empty-state message shown when no command matches. |
footer | z-cmd-footer | yes | yes | Bottom hint bar. |
footer-close | z-cmd-footer-item z-cmd-footer-close | yes | yes | Close button with the Esc hint. |
footer-group | z-cmd-footer-group | yes | yes | Group of navigation hints. |
footer-item | z-cmd-footer-item | yes | yes | Single hint: icon keycaps plus a label. |
footer-kbd | z-kbd | yes | yes | Keycap inside a footer hint. |
item | — | yes | yes | One command row (role="option"). |
item-active | z-active | yes | no | Class on the focused command. |
item-content | z-cmd-item-content | yes | yes | Text column: label and optional description. |
item-disabled | z-disabled | yes | no | Class on disabled commands. |
item-header | z-nav-header | yes | yes | Group header row. |
item-icon | z-custom-select-item-icon | yes | yes | Wrapper for the command's icon. |
item-link | — | yes | yes | Clickable link covering the command row. |
item-shortcut | z-cmd-item-shortcut | yes | yes | Keycap hint container on the right. |
item-subtitle | z-cmd-item-subtitle | yes | yes | Secondary description line. |
item-text | — | yes | yes | Command label. |
item-wrapper | z-custom-select-item-wrapper | yes | yes | Layout wrapper for the icon and text column. |
kbd | — | yes | yes | Individual keycap. |
list | z-nav z-dropdown-nav z-overflow-auto z-cmd-list | yes | yes | Scrollable results listbox. |
overlay | z-modal | yes | yes | Modal overlay behind the palette. |
panel | z-cmd-panel | yes | yes | Panel holding the search field and results list. |
search | z-custom-select-search | yes | yes | Search field wrapper (role="search"). |
search-icon | — | yes | yes | Wrapper for the search icon. |
search-input | — | yes | yes | Combobox input that drives filtering. |
separator | z-nav-divider | yes | yes | Divider inserted between groups. |
CSS Variables
| Variable | Default | Scope | Description |
|---|---|---|---|
--z-cmd-bg | color-mix(in srgb, var(--z-muted) calc(var(--z-muted-o) * 0.75), var(--z-bg)) | .z-cmd | Background of the palette surface. |
--z-cmd-border-color | var(--z-border) | .z-cmd | Border and shadow color of the search divider. |
--z-cmd-border-color-o | var(--z-border-o) | .z-cmd | Opacity applied to the divider border color. |
--z-cmd-empty-padding | 2.5rem 1rem | .z-cmd | Padding of the empty-state message. |
--z-cmd-list-max-height | 18rem | .z-cmd | Maximum height of the results list before it scrolls. |
--z-cmd-offset-top | 10vh | .z-cmd | Top offset of the palette from the viewport edge. |
--z-cmd-panel-bg | var(--z-drop) | .z-cmd | Background of the panel. |
--z-cmd-panel-color | var(--z-drop-f) | .z-cmd | Text color of the panel. |
--z-cmd-panel-radius | 0.75rem | .z-cmd | Bottom corner radius of the panel. |
--z-cmd-radius | 0.875rem | .z-cmd | Corner radius of the dialog. |
--z-cmd-shadow | 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1) | .z-cmd | Drop shadow of the dialog. |
--z-cmd-width | 34rem | .z-cmd | Width of the palette dialog; feeds --z-modal-dialog-width. |
i18n Keys
| Key | Default | Placeholders | Description |
|---|---|---|---|
close-hint | Esc | — | Keycap text on the close button. Used in: footer-close. |
close-label | Close | — | Label and aria-label of the close button. Used in: footer-close. |
dialog-label | Command menu | — | Accessible name of the dialog. Used in: dialog. |
empty-message | No results found. | — | Text shown when no command matches the search. Used in: empty. |
list-label | Commands | — | Accessible name of the results listbox. Used in: list. |
navigate-label | Navigate | — | Footer label for the arrow-key hint. Used in: footer-item. |
search-placeholder | Search for apps and commands... | — | Placeholder and aria-label of the search input. Used in: search-input. |
select-label | Open | — | Footer label for the Enter hint. Used in: footer-item. |
Icon Keys
| Key | Icon | Description |
|---|---|---|
arrow-down | Down-arrow keycap in the navigate hint. | |
arrow-up | Up-arrow keycap in the navigate hint. | |
corner-down-left | Enter keycap in the select hint. | |
search | Icon in the search field; replace it via the icon attribute. Configured by the icon attribute. |
Events
| Event | Detail | Flags | Description |
|---|---|---|---|
z-cmd:before-hide · from DialogMixin | — | cancelable, bubbles | Fires before closing; call preventDefault() to abort. |
z-cmd:before-show · from DialogMixin | — | cancelable, bubbles | Fires before opening; call preventDefault() to abort. |
z-cmd:destroy · from DialogMixin | — | bubbles | Fires when the mounted DOM is removed, via unmount or destroy(). |
z-cmd:hidden · from DialogMixin | — | bubbles | Fires after the close transition completes and focus is restored to the opener. |
z-cmd:hide · from DialogMixin | — | bubbles | Fires when the dialog starts closing. |
z-cmd:mount · from DialogMixin | — | bubbles | Fires once when the dialog DOM is first mounted. |
z-cmd:search · from BaseSelectMixin | { value: string } | bubbles | Fires when the search term changes; detail.value carries the current term. |
z-cmd:select | { value: string; text: string; group: string; item: OptionItem; originalEvent: MouseEvent | KeyboardEvent | undefined } | cancelable, bubbles | Fires when a command is chosen; detail carries value, text, group, the option item, and the originating event. preventDefault() keeps the palette open. |
z-cmd:show · from DialogMixin | — | bubbles | Fires when the dialog starts opening, before the transition completes. |
z-cmd:shown · from DialogMixin | — | bubbles | Fires after the open transition completes. |
Methods
| Signature | Description |
|---|---|
destroy(removeHost?: boolean = false): Promise<void> | Closes and unmounts the dialog DOM; optionally removes the host element as well. |
hide(): Promise<void> | Closes the dialog and restores focus to the opener. |
show(trigger?: HTMLElement | null): Promise<void> | Opens the dialog; the trigger element receives focus back on close. |
toggle(trigger?: HTMLElement | null): Promise<void> | Opens the dialog if closed, otherwise closes it. |
Data Hooks
| Attribute | Values | Applies to | Role | Description |
|---|---|---|---|---|
data-close | — | external-trigger | trigger | Closes the dialog matched by the selector, or the nearest enclosing dialog when no value is given. |
data-host-inner · from Hwc | — | descendant | config | Marks the rendered inner wrapper so force-prevent-rerender can adopt server-rendered DOM without re-rendering. |
data-index | — | descendant | marker | Index of the command within its group; used to resolve Enter selection. |
data-key | — | descendant | marker | Group key of the command; used with data-index to resolve selection. |
data-open · from DialogMixin | — | external-trigger | trigger | Clicking the element opens the dialog matched by the selector without toggling. |
data-part | dialog, list, overlay, search-input | descendant | marker | Marks structural parts (overlay, dialog, list, search-input) for the component's DOM references. |
data-reactive · from Hwc | — | descendant | config | Opts the marked child (config script, data source, icons, or template) into live re-parsing when its DOM mutates. |
data-toggle · from DialogMixin | — | external-trigger | trigger | Clicking the element toggles the dialog matched by the selector (usually #id). |
Child Content
script[data-fn="config"][type="application/json"]
JSON configuration script parsed by the base class (i18n, cls, stl, floating).
| Attribute | Required | Type | Description |
|---|---|---|---|
data-fn | yes | config | Marks the script as configuration (value: config). |
data-reactive | no | boolean | Re-parses the configuration when the script mutates. |
select[data-fn="data-source"]
Hidden select holding the commands; nothing renders until the palette opens.
| Attribute | Required | Type | Description |
|---|---|---|---|
data-fn | yes | data-source | Marks the select as the data source (value: data-source). |
data-reactive | no | boolean | Re-parses the commands when the select mutates. |
optgroup · repeatable
Groups commands under a header and inserts a separator before later groups.
| Attribute | Required | Type | Description |
|---|---|---|---|
label | yes | string | Group header text; also the default group key. |
disabled | no | boolean | Makes the group non-selectable and skipped by keyboard navigation. |
data-key | no | string | Overrides the group key used in the parsed data. |
data-keywords | no | comma-separated string | Comma-separated keywords stored with the group's data. |
option · repeatable
One command within the group.
| Attribute | Required | Type | Description |
|---|---|---|---|
value | no | string | Command identifier emitted in event.detail.value. |
disabled | no | boolean | Makes the command non-selectable and skipped by keyboard navigation. |
selected | no | boolean | Marks the command as initially selected. |
data-keywords | no | comma-separated string | Extra search terms, comma-separated; searched alongside the label and value. |
data-description | no | string | Secondary line shown under the label; also searched. |
data-icon | no | string | Icon key resolved through $icons for this command. |
data-kbd | no | string | Keycap hint: + joins keys (⌘+K), spaces separate them (G S). |
data-shortcut | no | string | Alternative keycap hint, used when data-kbd is absent. |
option · repeatable
One ungrouped command.
| Attribute | Required | Type | Description |
|---|---|---|---|
value | no | string | Command identifier emitted in event.detail.value. |
disabled | no | boolean | Makes the command non-selectable and skipped by keyboard navigation. |
selected | no | boolean | Marks the command as initially selected. |
data-keywords | no | comma-separated string | Extra search terms, comma-separated. |
data-description | no | string | Secondary line shown under the label; also searched. |
data-icon | no | string | Icon key resolved through $icons for this command. |
data-kbd | no | string | Keycap hint: + joins keys (⌘+K), spaces separate them (G S). |
data-shortcut | no | string | Alternative keycap hint, used when data-kbd is absent. |
template[data-fn="icons"]
Instance-level icon repository.
| Attribute | Required | Type | Description |
|---|---|---|---|
data-fn | yes | icons | Marks the template as an icon source (value: icons). |
data-reactive | no | boolean | Re-parses the icons when the template mutates. |
* · repeatable
One icon element.
| Attribute | Required | Type | Description |
|---|---|---|---|
data-key | yes | string | Icon key referenced by data-icon or the icon attribute. |
template[data-fn="template"]
Deferred content template mounted by the base class.
| Attribute | Required | Type | Description |
|---|---|---|---|
data-fn | yes | template | Marks the template for deferred mounting (value: template). |
data-reactive | no | boolean | Re-parses the template when it mutates. |
CSS Classes
| Class | Role | Applies to | Description |
|---|---|---|---|
.z-active | state | .z-cmd | State class on the focused command. |
.z-cmd | root | z-cmd | Root palette class on the dialog. |
.z-cmd-empty | element | .z-cmd | Empty-state message styling. |
.z-cmd-footer | element | .z-cmd | Footer bar layout. |
.z-cmd-footer-close | element | .z-cmd | Close button styling. |
.z-cmd-footer-group | element | .z-cmd | Hint group layout. |
.z-cmd-footer-item | element | .z-cmd | Single hint layout. |
.z-cmd-item-content | element | .z-cmd | Text column layout. |
.z-cmd-item-shortcut | element | .z-cmd | Keycap hint layout. |
.z-cmd-item-subtitle | element | .z-cmd | Description line styling. |
.z-cmd-list | element | .z-cmd | Results list sizing and scrolling. |
.z-cmd-panel | element | .z-cmd | Panel surface styling. |
.z-custom-select-item-icon | element | .z-cmd | Command icon sizing. |
.z-hr | element | .z-cmd | Divider rule styling. |
.z-kbd | element | .z-cmd | Keycap styling. |
.z-nav-divider | element | .z-cmd | Group separator styling. |
.z-nav-header | element | .z-cmd | Group header styling. |
Keyboard
| Keys | Action | When |
|---|---|---|
| ArrowDown ArrowUp | Move to the next / previous enabled command, wrapping at the ends. | The palette is open |
| Home End | Jump to the first / last enabled command. | The palette is open |
| Enter | Select the focused command (z-cmd:select). | The palette is open |
| Escape | Close the palette and restore focus to the opener. | The palette is open |
Accessibility
| Part | ARIA | Description |
|---|---|---|
dialog | aria-label="${this.getI18nText('dialog-label', this.defaultI18n)}" aria-modal="true" role="dialog" | Modal dialog container (aria-modal), labelled by dialog-label. |
divider | — | Separator between the search field and the results. |
empty | aria-live="polite" role="status" | Status region announcing the empty message (aria-live="polite"). |
footer | — | Hint bar container. |
footer-close | aria-label="${closeLabel}" | Close button labelled by close-label. |
footer-group | — | Navigation hint group. |
footer-item | — | Single navigation hint. |
item | aria-disabled="${item.disabled ? 'true' : 'false'}" aria-selected="${isFocused ? 'true' : 'false'}" role="option" | Command option; aria-selected tracks focus and aria-disabled marks unavailable commands. |
item-content | — | Text column wrapper. |
item-header | role="presentation" | Group header (role="presentation"). |
item-icon | — | Command icon wrapper. |
item-link | aria-label="${item.text}" | Link labelled by the command text. |
item-shortcut | — | Keycap hint wrapper. |
item-subtitle | — | Description text. |
item-text | — | Command label text. |
item-wrapper | — | Layout wrapper for icon and text. |
list | aria-activedescendant="${activeDescendant ?? ''}" aria-label="${this.getI18nText('list-label', this.defaultI18n)}" role="listbox" | Listbox of commands; the active option is announced via aria-activedescendant. |
overlay | — | Overlay wrapper. |
panel | — | Panel wrapper. |
search | role="search" | Search landmark (role="search"). |
search-icon | — | Search icon wrapper. |
search-input | aria-autocomplete="list" aria-controls="${this.listboxId}" aria-expanded="${this.$open ? 'true' : 'false'}" aria-label="${searchPlaceholder}" role="combobox" | Combobox controlling the listbox; aria-expanded tracks the open state. |
separator | role="separator" | Group separator (role="separator"). |
- Disabled commands receive
aria-disabled="true"and are skipped by arrow-key navigation. - Focus moves to the search input on open; the listbox tracks the active option with
aria-activedescendant.