CommandPalette
Command palette for global shortcuts, plugin entries, and search actions.
Usage
Best Practices
- Keep
idstable across releases; use it for analytics, persistence, and permission checks instead of localized titles. - Put synonyms, aliases, plugin names, and localized search terms in
keywords; do not duplicate commands just to cover search variants. - Register global shortcuts in the app shell, then drive
v-model;shortcutis only a visible keyboard hint. - Use
footerfor source labels, result counts, or keyboard help. Useemptyto show the current query and suggest recovery actions. - Cap
maxHeightfor dense command sets so the overlay stays keyboard-scannable and does not push below the viewport.
API Reference
Props
| Name | Type | Default | Description |
|---|---|---|---|
modelValue | boolean | - | Visibility state |
commands | CommandPaletteItem[] | [] | Command list |
placeholder | string | 'Search commands' | Search placeholder |
emptyText | string | 'No commands found' | Empty text |
maxHeight | number | 320 | Max list height |
autoFocus | boolean | true | Auto focus input |
closeOnSelect | boolean | true | Close after select |
overlayClass | string | string[] | Record<string, boolean> | - | Custom overlay class |
panelClass | string | string[] | Record<string, boolean> | - | Custom panel class |
CommandPaletteItem
| Field | Type | Description |
|---|---|---|
id | string | Unique id |
title | string | Title |
description | string | Description |
keywords | string[] | Keywords |
icon | TxIconSource | string | Icon |
shortcut | string | Shortcut |
disabled | boolean | Disabled state |
Events
| Event | Payload | Description |
|---|---|---|
update:modelValue | (value) | Visibility state |
select | (item) | Select command |
open | - | Opened |
close | - | Closed |
update:query | (value) | Search input update |
Slots
| Slot | Props | Description |
|---|---|---|
empty | { query, emptyText } | Custom empty state |
footer | { query, visibleCount } | Custom footer area |
Launcher Scenario
Loading demo...
UX Notes
- Title, description, and
keywordsall participate in filtering. Put aliases, localized terms, and plugin keywords on the same command. iconaccepts an icon class orTxIconSource;shortcutonly renders the keyboard hint and does not register a global shortcut.disabledcommands remain visible but cannot be selected, which is useful for missing permissions, unsupported platforms, or disabled features.- Use
closeOnSelect=falsefor batch workflows or settings panels. The default closes the palette after selection.
Overview
modelValueis the single source of truth for visibility. The palette emitsopenwhen it becomes visible andclosewhen an existing open state is dismissed.- Search is local substring matching across
title,description, and everykeywordsentry. The component does not rank, debounce, or fetch remote results. ArrowDown/ArrowUpcycle through the visible commands and skip disabled ones, so the highlight never parks on an unusable command;Enterselects the active command;Escapecloses the overlay. The initial highlight lands on the first enabled command, and arrow navigation is a no-op when every command is disabled.- IME composition (
isComposing, keyCode229, or an active composition session) suppresses keyboard selection so Chinese/Japanese/Korean input is not submitted early. selectemits the originalCommandPaletteItem. Disabled commands stay visible asrole="option"witharia-disabled="true"and are removed from the tab order (tabindex="-1"); they never emitselect.closeOnSelect=falsekeeps the palette open after selection.
Technologies
- Reviewed against
packages/tuffex/packages/components/src/command-palette/src/types.ts,TxCommandPalette.vue, andcommand-palette.test.ts. - Existing tests cover local filtering and selection, disabled-command skipping with
aria-disabled/tabindexmarking, IME composition guarding, matched text highlighting, and customempty/footerslots. - Accessibility note: the overlay renders
role="dialog"witharia-modal="true"; keep the trigger label and placeholder specific enough for the current command domain, and do not treat the displayedshortcutas actual shortcut registration. - Component source:
packages/tuffex/packages/components/src/command-palette/src/TxCommandPalette.vue. - Types:
packages/tuffex/packages/components/src/command-palette/src/types.tsexportsCommandPaletteProps,CommandPaletteEmits,CommandPaletteItem, andCommandPaletteClassValue. - Verified coverage:
packages/tuffex/packages/components/src/command-palette/__tests__/command-palette.test.tsverifies filtering, select emits, disabled-command skipping andaria-disabled/tabindexmarking, IME guarding, match highlighting, and slots.查看源码packages/tuffex/packages/components/src/command-palette/index.ts