overlayshwcz-cmd

Command

Lazy-mounted modal command palette with live multi-token search, grouped actions, descriptions, and keycap hints.

Attributes

AttributeTypeDefaultDescription
placeholderstring''Overrides the search field placeholder from i18n.
shortcutstring''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-closebooleanfalseKeeps the palette open after an item is selected.
no-footerbooleanfalseHides the keyboard-hint and close bar.
iconstring''Icon key that replaces the default search icon.
Inherited from DialogMixin
AttributeTypeDefaultDescription
openboolean · reflectsfalseOpens the dialog on first render and stays in sync with show() and hide().
centerbooleanfalseVertically centers the panel within the overlay.
containerbooleanfalseAdds z-modal-container to the overlay for a contained presentation.
fullbooleanfalseAdds z-modal-full to the overlay for a full-screen presentation.
stackbooleanfalseKeeps other open dialogs open; without it, showing this dialog hides them. Stacked overlays receive increasing z-index.
inlinebooleanfalseKeeps the component in its original DOM position instead of teleporting it to document.body.
no-bg-closebooleanfalseDisables closing when the overlay background is clicked.
no-esc-closebooleanfalseDisables closing with the Esc key.
unmountbooleanfalseRemoves 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-labelstring''Accessible name for the panel when no aria-labelledby is set.
aria-labelledbystring''Id of the element that names the panel; takes precedence over aria-label.
Inherited from Hwc
AttributeTypeDefaultDescription
i18nstring''Per-instance text overrides as key: text pairs, merged over the global z-i18n script and the built-in defaults.
floatingstring''Floating UI placement options (for example offset and shiftPadding) parsed as key: value pairs.
force-prevent-rerenderbooleanfalseSkips re-rendering after the first render; an existing data-host-inner child is adopted as the rendered DOM.
templatestring''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
AttributeTypeDefaultDescription
clsstring''Adds classes to named parts as key: classes pairs; a plain string targets the default part.
stlstring''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

KeyDefault classclsstlDescription
dialogz-modal-dialog z-cmdyesyesDialog container; the default cls and stl target.
dividerz-hryesyesHorizontal rule between the search field and the results.
emptyz-cmd-emptyyesyesEmpty-state message shown when no command matches.
footerz-cmd-footeryesyesBottom hint bar.
footer-closez-cmd-footer-item z-cmd-footer-closeyesyesClose button with the Esc hint.
footer-groupz-cmd-footer-groupyesyesGroup of navigation hints.
footer-itemz-cmd-footer-itemyesyesSingle hint: icon keycaps plus a label.
footer-kbdz-kbdyesyesKeycap inside a footer hint.
item—yesyesOne command row (role="option").
item-activez-activeyesnoClass on the focused command.
item-contentz-cmd-item-contentyesyesText column: label and optional description.
item-disabledz-disabledyesnoClass on disabled commands.
item-headerz-nav-headeryesyesGroup header row.
item-iconz-custom-select-item-iconyesyesWrapper for the command's icon.
item-link—yesyesClickable link covering the command row.
item-shortcutz-cmd-item-shortcutyesyesKeycap hint container on the right.
item-subtitlez-cmd-item-subtitleyesyesSecondary description line.
item-text—yesyesCommand label.
item-wrapperz-custom-select-item-wrapperyesyesLayout wrapper for the icon and text column.
kbd—yesyesIndividual keycap.
listz-nav z-dropdown-nav z-overflow-auto z-cmd-listyesyesScrollable results listbox.
overlayz-modalyesyesModal overlay behind the palette.
panelz-cmd-panelyesyesPanel holding the search field and results list.
searchz-custom-select-searchyesyesSearch field wrapper (role="search").
search-icon—yesyesWrapper for the search icon.
search-input—yesyesCombobox input that drives filtering.
separatorz-nav-divideryesyesDivider inserted between groups.

CSS Variables

VariableDefaultScopeDescription
--z-cmd-bgcolor-mix(in srgb, var(--z-muted) calc(var(--z-muted-o) * 0.75), var(--z-bg)).z-cmdBackground of the palette surface.
--z-cmd-border-colorvar(--z-border).z-cmdBorder and shadow color of the search divider.
--z-cmd-border-color-ovar(--z-border-o).z-cmdOpacity applied to the divider border color.
--z-cmd-empty-padding2.5rem 1rem.z-cmdPadding of the empty-state message.
--z-cmd-list-max-height18rem.z-cmdMaximum height of the results list before it scrolls.
--z-cmd-offset-top10vh.z-cmdTop offset of the palette from the viewport edge.
--z-cmd-panel-bgvar(--z-drop).z-cmdBackground of the panel.
--z-cmd-panel-colorvar(--z-drop-f).z-cmdText color of the panel.
--z-cmd-panel-radius0.75rem.z-cmdBottom corner radius of the panel.
--z-cmd-radius0.875rem.z-cmdCorner radius of the dialog.
--z-cmd-shadow0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1).z-cmdDrop shadow of the dialog.
--z-cmd-width34rem.z-cmdWidth of the palette dialog; feeds --z-modal-dialog-width.

i18n Keys

KeyDefaultPlaceholdersDescription
close-hintEsc—Keycap text on the close button. Used in: footer-close.
close-labelClose—Label and aria-label of the close button. Used in: footer-close.
dialog-labelCommand menu—Accessible name of the dialog. Used in: dialog.
empty-messageNo results found.—Text shown when no command matches the search. Used in: empty.
list-labelCommands—Accessible name of the results listbox. Used in: list.
navigate-labelNavigate—Footer label for the arrow-key hint. Used in: footer-item.
search-placeholderSearch for apps and commands...—Placeholder and aria-label of the search input. Used in: search-input.
select-labelOpen—Footer label for the Enter hint. Used in: footer-item.

Icon Keys

KeyIconDescription
arrow-downDown-arrow keycap in the navigate hint.
arrow-upUp-arrow keycap in the navigate hint.
corner-down-leftEnter keycap in the select hint.
searchIcon in the search field; replace it via the icon attribute. Configured by the icon attribute.

Events

EventDetailFlagsDescription
z-cmd:before-hide · from DialogMixin—cancelable, bubblesFires before closing; call preventDefault() to abort.
z-cmd:before-show · from DialogMixin—cancelable, bubblesFires before opening; call preventDefault() to abort.
z-cmd:destroy · from DialogMixin—bubblesFires when the mounted DOM is removed, via unmount or destroy().
z-cmd:hidden · from DialogMixin—bubblesFires after the close transition completes and focus is restored to the opener.
z-cmd:hide · from DialogMixin—bubblesFires when the dialog starts closing.
z-cmd:mount · from DialogMixin—bubblesFires once when the dialog DOM is first mounted.
z-cmd:search · from BaseSelectMixin{ value: string }bubblesFires 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, bubblesFires 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—bubblesFires when the dialog starts opening, before the transition completes.
z-cmd:shown · from DialogMixin—bubblesFires after the open transition completes.

Methods

SignatureDescription
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

AttributeValuesApplies toRoleDescription
data-close—external-triggertriggerCloses the dialog matched by the selector, or the nearest enclosing dialog when no value is given.
data-host-inner · from Hwc—descendantconfigMarks the rendered inner wrapper so force-prevent-rerender can adopt server-rendered DOM without re-rendering.
data-index—descendantmarkerIndex of the command within its group; used to resolve Enter selection.
data-key—descendantmarkerGroup key of the command; used with data-index to resolve selection.
data-open · from DialogMixin—external-triggertriggerClicking the element opens the dialog matched by the selector without toggling.
data-partdialog, list, overlay, search-inputdescendantmarkerMarks structural parts (overlay, dialog, list, search-input) for the component's DOM references.
data-reactive · from Hwc—descendantconfigOpts the marked child (config script, data source, icons, or template) into live re-parsing when its DOM mutates.
data-toggle · from DialogMixin—external-triggertriggerClicking 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).

AttributeRequiredTypeDescription
data-fnyesconfigMarks the script as configuration (value: config).
data-reactivenobooleanRe-parses the configuration when the script mutates.

select[data-fn="data-source"]

Hidden select holding the commands; nothing renders until the palette opens.

AttributeRequiredTypeDescription
data-fnyesdata-sourceMarks the select as the data source (value: data-source).
data-reactivenobooleanRe-parses the commands when the select mutates.

optgroup · repeatable

Groups commands under a header and inserts a separator before later groups.

AttributeRequiredTypeDescription
labelyesstringGroup header text; also the default group key.
disablednobooleanMakes the group non-selectable and skipped by keyboard navigation.
data-keynostringOverrides the group key used in the parsed data.
data-keywordsnocomma-separated stringComma-separated keywords stored with the group's data.

option · repeatable

One command within the group.

AttributeRequiredTypeDescription
valuenostringCommand identifier emitted in event.detail.value.
disablednobooleanMakes the command non-selectable and skipped by keyboard navigation.
selectednobooleanMarks the command as initially selected.
data-keywordsnocomma-separated stringExtra search terms, comma-separated; searched alongside the label and value.
data-descriptionnostringSecondary line shown under the label; also searched.
data-iconnostringIcon key resolved through $icons for this command.
data-kbdnostringKeycap hint: + joins keys (⌘+K), spaces separate them (G S).
data-shortcutnostringAlternative keycap hint, used when data-kbd is absent.

option · repeatable

One ungrouped command.

AttributeRequiredTypeDescription
valuenostringCommand identifier emitted in event.detail.value.
disablednobooleanMakes the command non-selectable and skipped by keyboard navigation.
selectednobooleanMarks the command as initially selected.
data-keywordsnocomma-separated stringExtra search terms, comma-separated.
data-descriptionnostringSecondary line shown under the label; also searched.
data-iconnostringIcon key resolved through $icons for this command.
data-kbdnostringKeycap hint: + joins keys (⌘+K), spaces separate them (G S).
data-shortcutnostringAlternative keycap hint, used when data-kbd is absent.

template[data-fn="icons"]

Instance-level icon repository.

AttributeRequiredTypeDescription
data-fnyesiconsMarks the template as an icon source (value: icons).
data-reactivenobooleanRe-parses the icons when the template mutates.

* · repeatable

One icon element.

AttributeRequiredTypeDescription
data-keyyesstringIcon key referenced by data-icon or the icon attribute.

template[data-fn="template"]

Deferred content template mounted by the base class.

AttributeRequiredTypeDescription
data-fnyestemplateMarks the template for deferred mounting (value: template).
data-reactivenobooleanRe-parses the template when it mutates.

CSS Classes

ClassRoleApplies toDescription
.z-activestate.z-cmdState class on the focused command.
.z-cmdrootz-cmdRoot palette class on the dialog.
.z-cmd-emptyelement.z-cmdEmpty-state message styling.
.z-cmd-footerelement.z-cmdFooter bar layout.
.z-cmd-footer-closeelement.z-cmdClose button styling.
.z-cmd-footer-groupelement.z-cmdHint group layout.
.z-cmd-footer-itemelement.z-cmdSingle hint layout.
.z-cmd-item-contentelement.z-cmdText column layout.
.z-cmd-item-shortcutelement.z-cmdKeycap hint layout.
.z-cmd-item-subtitleelement.z-cmdDescription line styling.
.z-cmd-listelement.z-cmdResults list sizing and scrolling.
.z-cmd-panelelement.z-cmdPanel surface styling.
.z-custom-select-item-iconelement.z-cmdCommand icon sizing.
.z-hrelement.z-cmdDivider rule styling.
.z-kbdelement.z-cmdKeycap styling.
.z-nav-dividerelement.z-cmdGroup separator styling.
.z-nav-headerelement.z-cmdGroup header styling.

Keyboard

KeysActionWhen
ArrowDown ArrowUpMove to the next / previous enabled command, wrapping at the ends.The palette is open
Home EndJump to the first / last enabled command.The palette is open
EnterSelect the focused command (z-cmd:select).The palette is open
EscapeClose the palette and restore focus to the opener.The palette is open

Accessibility

PartARIADescription
dialogaria-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.
emptyaria-live="polite" role="status"Status region announcing the empty message (aria-live="polite").
footer—Hint bar container.
footer-closearia-label="${closeLabel}"Close button labelled by close-label.
footer-group—Navigation hint group.
footer-item—Single navigation hint.
itemaria-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-headerrole="presentation"Group header (role="presentation").
item-icon—Command icon wrapper.
item-linkaria-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.
listaria-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.
searchrole="search"Search landmark (role="search").
search-icon—Search icon wrapper.
search-inputaria-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.
separatorrole="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.