Skip to content
MarkasUI
Type to search

    Guide

    MarkasUI

    Form

    Feedback

    Overlay

    Navigation

    Data

    Sections

    Animations

    Backgrounds

    Buttons

    Templates

    Pages

    Command Palette

    Searchable list of commands in a modal dialog, filtered as you type, with arrow key navigation and an optional Ctrl+K or Cmd+K shortcut.

    Suggestions
    Calendar
    Search emoji
    Calculator
    Settings
    ProfileCtrl+P
    BillingCtrl+B
    SettingsCtrl+S
    Suggestions
    Calendar
    Search emoji
    Calculator
    Settings
    ProfileCtrl+P
    BillingCtrl+B
    SettingsCtrl+S
    Suggestions
    Calendar
    Search emoji
    Calculator
    Settings
    ProfileCtrl+P
    BillingCtrl+B
    SettingsCtrl+S
    Suggestions
    Calendar
    Search emoji
    Calculator
    Settings
    ProfileCtrl+P
    BillingCtrl+B
    SettingsCtrl+S
    Suggestions
    Calendar
    Search emoji
    Calculator
    Settings
    ProfileCtrl+P
    BillingCtrl+B
    SettingsCtrl+S
    <x-markas.command
        hotkey
        :items="[
            ['group' => 'Suggestions', 'label' => 'Calendar', 'value' => 'calendar'],
            ['group' => 'Suggestions', 'label' => 'Search emoji', 'value' => 'emoji'],
            ['group' => 'Suggestions', 'label' => 'Calculator', 'value' => 'calculator'],
            ['group' => 'Settings', 'label' => 'Profile', 'value' => 'profile', 'shortcut' => 'Ctrl+P'],
            ['group' => 'Settings', 'label' => 'Billing', 'value' => 'billing', 'shortcut' => 'Ctrl+B'],
            ['group' => 'Settings', 'label' => 'Settings', 'value' => 'settings', 'shortcut' => 'Ctrl+S'],
        ]"
    >
        <x-slot:trigger>
            <x-markas.button variant="secondary">Open command palette</x-markas.button>
        </x-slot:trigger>
    </x-markas.command>
    import { Button } from "@/components/markas/Button";
    import { Command } from "@/components/markas/Command";
    
    const items = [
      { group: "Suggestions", label: "Calendar", value: "calendar" },
      { group: "Suggestions", label: "Search emoji", value: "emoji" },
      { group: "Suggestions", label: "Calculator", value: "calculator" },
      { group: "Settings", label: "Profile", value: "profile", shortcut: "Ctrl+P" },
      { group: "Settings", label: "Billing", value: "billing", shortcut: "Ctrl+B" },
      {
        group: "Settings",
        label: "Settings",
        value: "settings",
        shortcut: "Ctrl+S",
      },
    ];
    
    export default function CommandExample() {
      return (
        <Command
          hotkey
          items={items}
          trigger={<Button variant="secondary">Open command palette</Button>}
        />
      );
    }
    <script setup lang="ts">
    import Button from "@/components/markas/Button.vue";
    import Command from "@/components/markas/Command.vue";
    
    const items = [
      { group: "Suggestions", label: "Calendar", value: "calendar" },
      { group: "Suggestions", label: "Search emoji", value: "emoji" },
      { group: "Suggestions", label: "Calculator", value: "calculator" },
      { group: "Settings", label: "Profile", value: "profile", shortcut: "Ctrl+P" },
      { group: "Settings", label: "Billing", value: "billing", shortcut: "Ctrl+B" },
      {
        group: "Settings",
        label: "Settings",
        value: "settings",
        shortcut: "Ctrl+S",
      },
    ];
    </script>
    
    <template>
      <Command hotkey :items="items">
        <template #trigger>
          <Button variant="secondary">Open command palette</Button>
        </template>
      </Command>
    </template>
    <script lang="ts">
      import Button from "$lib/components/markas/Button.svelte";
      import Command from "$lib/components/markas/Command.svelte";
    
      const items = [
        { group: "Suggestions", label: "Calendar", value: "calendar" },
        { group: "Suggestions", label: "Search emoji", value: "emoji" },
        { group: "Suggestions", label: "Calculator", value: "calculator" },
        {
          group: "Settings",
          label: "Profile",
          value: "profile",
          shortcut: "Ctrl+P",
        },
        {
          group: "Settings",
          label: "Billing",
          value: "billing",
          shortcut: "Ctrl+B",
        },
        {
          group: "Settings",
          label: "Settings",
          value: "settings",
          shortcut: "Ctrl+S",
        },
      ];
    </script>
    
    <Command hotkey {items}>
      {#snippet trigger()}
        <Button variant="secondary">Open command palette</Button>
      {/snippet}
    </Command>
    ---
    import Button from "@/components/markas/Button.astro";
    import Command from "@/components/markas/Command.astro";
    
    const items = [
      { group: "Suggestions", label: "Calendar", value: "calendar" },
      { group: "Suggestions", label: "Search emoji", value: "emoji" },
      { group: "Suggestions", label: "Calculator", value: "calculator" },
      { group: "Settings", label: "Profile", value: "profile", shortcut: "Ctrl+P" },
      { group: "Settings", label: "Billing", value: "billing", shortcut: "Ctrl+B" },
      {
        group: "Settings",
        label: "Settings",
        value: "settings",
        shortcut: "Ctrl+S",
      },
    ];
    ---
    
    <Command hotkey items={items}>
      <Button slot="trigger" variant="secondary">Open command palette</Button>
    </Command>
    import { Component } from "@angular/core";
    import { Button } from "./markas/button.component";
    import { Command } from "./markas/command.component";
    
    @Component({
      selector: "markas-example",
      imports: [Button, Command],
      template: `
        <markas-command hotkey [items]="items">
          <button markas-button trigger variant="secondary">
            Open command palette
          </button>
        </markas-command>
      `,
    })
    export default class CommandExample {
      protected readonly items = [
        { group: "Suggestions", label: "Calendar", value: "calendar" },
        { group: "Suggestions", label: "Search emoji", value: "emoji" },
        { group: "Suggestions", label: "Calculator", value: "calculator" },
        {
          group: "Settings",
          label: "Profile",
          value: "profile",
          shortcut: "Ctrl+P",
        },
        {
          group: "Settings",
          label: "Billing",
          value: "billing",
          shortcut: "Ctrl+B",
        },
        {
          group: "Settings",
          label: "Settings",
          value: "settings",
          shortcut: "Ctrl+S",
        },
      ];
    }

    Examples

    Search field trigger

    Pages
    Dashboard
    Invoices
    Customers
    Actions
    Create invoice
    Add customer
    Pages
    Dashboard
    Invoices
    Customers
    Actions
    Create invoice
    Add customer
    Pages
    Dashboard
    Invoices
    Customers
    Actions
    Create invoice
    Add customer
    Pages
    Dashboard
    Invoices
    Customers
    Actions
    Create invoice
    Add customer
    Pages
    Dashboard
    Invoices
    Customers
    Actions
    Create invoice
    Add customer

    With links

    Components
    Button Modal

    Icon trigger

    MarkasUI
    Workspace
    Create projectCtrl+N
    Invite memberCtrl+I
    Account
    Switch theme
    Sign out
    MarkasUI
    Workspace
    Create projectCtrl+N
    Invite memberCtrl+I
    Account
    Switch theme
    Sign out
    MarkasUI
    Workspace
    Create projectCtrl+N
    Invite memberCtrl+I
    Account
    Switch theme
    Sign out
    MarkasUI
    Workspace
    Create projectCtrl+N
    Invite memberCtrl+I
    Account
    Switch theme
    Sign out
    MarkasUI
    Workspace
    Create projectCtrl+N
    Invite memberCtrl+I
    Account
    Switch theme
    Sign out

    Installation

    npx markasui@latest add command

    Usage

    <x-markas.command
        hotkey
        :items="[
            ['group' => 'Navigation', 'label' => 'Dashboard', 'href' => '/dashboard'],
            ['group' => 'Navigation', 'label' => 'Projects', 'href' => '/projects'],
            ['group' => 'Actions', 'label' => 'Create project', 'value' => 'create', 'shortcut' => 'Ctrl+N'],
            ['group' => 'Actions', 'label' => 'Invite member', 'value' => 'invite'],
        ]"
        x-on:markas-select="console.log($event.detail)"
    >
        <x-slot:trigger>
            <x-markas.button variant="secondary">Search</x-markas.button>
        </x-slot:trigger>
    </x-markas.command>

    Needs Alpine.js. Choosing a command dispatches a markas-select event with the value in $event.detail. In Livewire: x-on:markas-select="$wire.run($event.detail)".

    Livewire

    <x-markas.command hotkey :items="$commands" wire:markas-select="go($event.detail)" />

    wire:markas-select calls a Livewire action with the picked value. The Ctrl+K listener is removed when the component leaves the page, so wire:navigate never stacks listeners.

    import { Button } from "@/components/markas/Button";
    import { Command } from "@/components/markas/Command";
    
    <Command
      hotkey
      trigger={<Button variant="secondary">Search</Button>}
      items={[
        { group: "Navigation", label: "Dashboard", href: "/dashboard" },
        { group: "Navigation", label: "Projects", href: "/projects" },
        {
          group: "Actions",
          label: "Create project",
          value: "create",
          shortcut: "Ctrl+N",
        },
        { group: "Actions", label: "Invite member", value: "invite" },
      ]}
      onSelect={(value) => console.log(value)}
    />;
    <template>
      <Command
        hotkey
        :items="[
          { group: 'Navigation', label: 'Dashboard', href: '/dashboard' },
          { group: 'Navigation', label: 'Projects', href: '/projects' },
          {
            group: 'Actions',
            label: 'Create project',
            value: 'create',
            shortcut: 'Ctrl+N',
          },
          { group: 'Actions', label: 'Invite member', value: 'invite' },
        ]"
        @select="(value) => console.log(value)"
      >
        <template #trigger>
          <Button variant="secondary">Search</Button>
        </template>
      </Command>
    </template>
    <script lang="ts">
      import Button from "$lib/components/markas/Button.svelte";
      import Command from "$lib/components/markas/Command.svelte";
    
      const items = [
        { group: "Navigation", label: "Dashboard", href: "/dashboard" },
        { group: "Navigation", label: "Projects", href: "/projects" },
        {
          group: "Actions",
          label: "Create project",
          value: "create",
          shortcut: "Ctrl+N",
        },
        { group: "Actions", label: "Invite member", value: "invite" },
      ];
    </script>
    
    <Command hotkey {items} onselect={(value) => console.log(value)}>
      {#snippet trigger()}
        <Button variant="secondary">Search</Button>
      {/snippet}
    </Command>
    ---
    import Button from "@/components/markas/Button.astro";
    import Command from "@/components/markas/Command.astro";
    
    const items = [
      { group: "Navigation", label: "Dashboard", href: "/dashboard" },
      { group: "Navigation", label: "Projects", href: "/projects" },
      { group: "Actions", label: "Create project", value: "create", shortcut: "Ctrl+N" },
      { group: "Actions", label: "Invite member", value: "invite" },
    ];
    ---
    
    <Command hotkey items={items}>
      <Button slot="trigger" variant="secondary">Search</Button>
    </Command>
    
    <script>
      document.addEventListener("markas-select", (event) => {
        console.log((event as CustomEvent<string>).detail);
      });
    </script>

    A small bundled script filters the list and handles the keyboard. Choosing a command dispatches a bubbling markas-select event with the value in detail.

    import { Component } from "@angular/core";
    import { Button } from "./markas/button.component";
    import { Command } from "./markas/command.component";
    
    @Component({
      selector: "app-launcher",
      imports: [Button, Command],
      template: `
        <markas-command hotkey [items]="items" (selected)="run($event)">
          <button markas-button trigger variant="secondary">Search</button>
        </markas-command>
      `,
    })
    export class Launcher {
      readonly items = [
        { group: "Navigation", label: "Dashboard", href: "/dashboard" },
        { group: "Navigation", label: "Projects", href: "/projects" },
        {
          group: "Actions",
          label: "Create project",
          value: "create",
          shortcut: "Ctrl+N",
        },
        { group: "Actions", label: "Invite member", value: "invite" },
      ];
    
      run(value: string) {}
    }
    • The search is a case-insensitive match on the label. The search resets when the dialog closes.
    • Items with href navigate like normal links and also call the select callback.
    • Attributes and class go to the dialog element.
    • placeholderLabel, emptyLabel, searchLabel, and dialogLabel default to English. Translate them for other languages.

    Props

    NameTypeDefaultDescription
    items{ group, label, value?, href?, shortcut? }[][]Commands. Items are grouped by group in order of first appearance. Items with href render as links.
    triggerslot / ReactNode / snippet-Element that opens the palette on click, usually a button. Angular: an element with the trigger attribute.
    hotkeybooleanfalseCtrl+K or Cmd+K anywhere on the page opens and closes the palette.
    placeholderLabelstringType a command or search...Placeholder of the search field.
    emptyLabelstringNo results found.Message shown when no command matches the search.
    searchLabelstringSearch commandsAccessible name of the search field.
    dialogLabelstringCommand paletteAccessible name of the dialog and the result list.
    onSelect / @select / markas-select(value: string) => void-Called when a command is chosen, with its value (or label when value is empty). Svelte: onselect. Blade and Astro dispatch a bubbling markas-select event with the value in detail.
    idstringautoDialog id. The list and options use it as a prefix.
    selectedoutput<string>-Angular only. Emits the value (or label) of the chosen command.

    Accessibility

    • Native modal dialog: focus moves to the search field on open, stays inside the dialog, and returns to the trigger on close.
    • The search field is a combobox with aria-controls pointing to the role=listbox result list and aria-activedescendant on the highlighted option.
    • Arrow Down and Arrow Up move the highlight (wrapping at the ends), Enter runs the highlighted command, Escape closes the dialog.
    • Options are grouped with role=group labelled by the group heading; the empty message replaces the list when nothing matches.

    Related components

    More overlay components with the same classes in every framework.