Skip to content
HyperUX Experimental
Demo

Note: This pattern is extra experimental because it composes other HyperUX primitives.

Press to open from anywhere.


Alpine.js Command Palette

huxCommandPalette is a keyboard-first selector that composes huxDialog and huxCombobox behavior. It filters named commands and supports both link navigation and custom action dispatch.

Because this pattern composes other primitives, changes in dialog/combobox behavior may affect it. Treat the API as extra experimental.

The live demo on this page uses shortcutKey: 'p' so it does not conflict with the global site search shortcut.

API

huxCommandPalette(config)

Returns an Alpine data object with:

Internal helper methods are private implementation details and are not part of the supported API contract.

Options

Use hyphen-case for action names. Non-hyphen-case names will be ignored.

Quick Start

<div
  x-data="huxCommandPalette({
    paletteId: 'docs-palette',
    paletteItems: [
      { label: 'Docs', href: '/patterns/command-palette' },
      { label: 'Open GitHub', href: 'https://github.com/markmead/hyperux', target: '_blank' },
      { label: 'Copy URL', action: 'copy-page-url' }
    ],
    shortcutKey: 'p'
  })"
  x-on:keydown.window="handleGlobalShortcut($event)"
  x-on:hux-command-palette:docs-palette:copy-page-url.window="navigator.clipboard.writeText(location.href).catch(() => {})"
>
  ...
</div>

Common Usage Patterns

Internal + External + Action Items

huxCommandPalette({
  paletteItems: [
    { label: 'Scroll Spy Docs', href: '/patterns/scroll-spy' },
    { label: 'Open GitHub', href: 'https://github.com/markmead/hyperux', target: '_blank' },
    { label: 'Copy URL', action: 'copy-page-url' },
  ],
})

Change Shortcut Key

huxCommandPalette({
  paletteItems: [{ label: 'Open Docs', href: '/patterns' }],
  shortcutKey: 'p',
})

Behavior Contract

Error Handling

Accessibility Notes

Notes