BladewindUI: Command Palette Component

Command Palette

Command Palette provides a fast, searchable way to find and run actions using the keyboard. Open it with a configurable shortcut or helper method, then start typing to filter available actions. Actions can be organized into groups, and the palette supports full keyboard navigation, asynchronous results, and dark mode.


<x-bladewind::button onclick="openCommandPalette('app-commands')">
    Search commands
</x-bladewind::button>
        
<x-bladewind::command-palette name="app-commands"
    label="Command palette" placeholder="Search for a command or page…">
    <x-bladewind::command-palette.group name="navigate" label="Navigate">
        <x-bladewind::command-palette.item name="dashboard"
            label="Dashboard"
            description="Overview of your workspace"
            href="#dashboard"
            icon="home" />
        <x-bladewind::command-palette.item name="orders"
            label="Orders"
            description="Review recent orders"
            href="#orders"
            icon="shopping-bag" />
        <x-bladewind::command-palette.item name="customers"
            label="Customers"
            href="#customers" icon="users" />
    </x-bladewind::command-palette.group>
    ...
</x-bladewind::command-palette>
        
    

Opening the Palette

Command Palette renders hidden. It is not tied to a trigger button by default. Open it with its keyboard shortcut, or call openCommandPalette(name) from any element. Try the demo above with Ctrl + K ( + K on macOS).

The shortcut works even while focus sits inside another field on the page, which is the convention command palettes across editors, chat apps, and issue trackers already share.

Searching and Grouped Results

As you type, Command Palette filters items by their label, description, and optional keywords attribute. Matching is case-insensitive and works on partial text. Groups are automatically hidden when none of their items match. For example, try searching for add new in the demo above. It finds Create order through its keywords, even though those words do not appear in the visible label.

For server-side search, Command Palette emits bladewind:command-palette:search with the current query on every keystroke. Listen for this event to fetch and display matching results asynchronously.

While results are loading, set loading="true" or call setCommandPaletteLoading(name, true). The built-in empty state remains hidden until loading is complete.

Keyboard Behavior

Focus stays in the search field the entire time the palette is open. Navigation moves a highlighted state between items instead of moving real focus, so screen readers track the current option through aria-activedescendant on the search field.

KeyBehavior
Up Arrow or Down ArrowMove the highlight to the previous or next visible, enabled item.
Home or EndJump the highlight to the first or last visible item.
EnterActivate the highlighted item.
EscapeClose the palette and restore focus to whatever opened it.
TabCycles between the search field and the close button while the palette is open.

Links, Actions, and Disabled Items

An item with href renders as a link and navigates normally. An item without href renders as a button, for actions handled entirely in JavaScript through the select event. Disabled items stay visible but cannot be highlighted or activated.

Dark Mode

Command Palette follows the page dark class and keeps the backdrop, panel, highlighted item, description, and shortcut key contrast readable.

Events

Before events are cancelable. Call preventDefault() to stop the related change. All event names start with bladewind:command-palette:. Item events include the item name and, for links, the destination.

Event suffixWhen it runs
before-open,
before-close
Before the palette opens or closes.
opened, closedAfter the palette finishes opening or closing.
before-selectBefore an item is activated. Preventing this stops navigation and the close-on-select behavior.
selectAfter an item is activated.
searchOn every keystroke in the search field, with the current query.

Full List of Attributes

Command Palette Attributes

AttributeDefaultDescription
nameGeneratedUnique public helper and DOM scope.
labelCommand paletteAccessible dialog and listbox name.
placeholderSearch for a command…Search field placeholder text.
search-labelSame as labelAccessible name for the search field.
shortcutmod+kGlobal open/close shortcut. mod resolves to Ctrl or Cmd. Empty disables the shortcut.
sizemediumtiny, small, medium, big, large, xl, or omg.
openfalseInitial open state.
loadingfalseShows the loading row and suppresses the empty state.
empty-textNo results found.Text shown when nothing matches.
loading-textLoading…Text shown while loading is true.
close-on-selecttrueCloses the palette after an item is activated.
backdrop-can-closetrueAllows a backdrop click to close the palette.
escape-can-closetrueAllows Escape to close the palette.
close-labelClose command paletteAccessible label for the close button.

Command Palette Group Attributes

AttributeDefaultDescription
nameRequiredName scoped to its Command Palette.
labelRequiredVisible and accessible section heading.

Command Palette Item Attributes

AttributeDefaultDescription
nameRequiredEvent identifier for the item.
labelemptyVisible and accessible label, and part of the search text.
descriptionnullSecondary text, also matched while searching.
iconnullHeroicon name.
icon-typeoutlineIcon type.
icon-diremptyCustom icon directory.
shortcutnullDisplay-only key combination, for example Ctrl+N. Rendered as individual <kbd> keys.
keywordsemptyExtra terms matched while searching but not displayed.
hrefnullLink destination. Omit for a button action handled through the select event.
disabledfalseRemoves the item from highlighting and activation.
externalfalseAdds external link semantics and indicator.
targetnullLink target.

Slots

SlotDescription
command-palette defaultCommand palette groups and items.
command-palette footerContent appended after the built-in keyboard hints in the footer.
group defaultItems belonging to the group.
item defaultCustom item copy while Command Palette keeps the option and search semantics.

JavaScript API

Helpers return true on success or when the requested state already applies. They return false for a missing target or a canceled event.

openCommandPalette('app-commands');
closeCommandPalette('app-commands');
toggleCommandPalette('app-commands');
resetCommandPalette('app-commands');
setCommandPaletteLoading('app-commands', true);

Command Palette with all attributes defined

<x-bladewind::command-palette
    name="app-commands"
    label="Command palette"
    placeholder="Search for a command or page…"
    search-label="Command palette"
    shortcut="mod+k"
    size="medium"
    open="false"
    loading="false"
    empty-text="No results found."
    loading-text="Loading…"
    close-on-select="true"
    backdrop-can-close="true"
    escape-can-close="true"
    close-label="Close command palette"
    class="app-command-palette"
    data-region="app">
    <x-bladewind::command-palette.group name="actions" label="Actions">
        <x-bladewind::command-palette.item name="new-order" label="Create order" description="Start a manual order" icon="plus-circle" icon-type="outline" icon-dir="" shortcut="Ctrl+N" keywords="add new" href="/orders/new" disabled="false" external="false" target="_self" class="new-order-item" data-area="orders" />
    </x-bladewind::command-palette.group>
    <x-slot:footer>Signed in as Ama Mensah</x-slot:footer>
</x-bladewind::command-palette>
The source files for this component are available in resources > views > components > bladewind > command-palette