Skip to content
Guides
Navigation
Feedback
Overlays
Layout
Data Display
Forms
.md

Navigation

command

Command palette on a native dialog: opens with Cmd/Ctrl+K, filters grouped items as you type, navigates to links or dispatches a command-select event.

Suggestions
Calendar
Search emoji
Calculator
Settings
Profile ⌘P
Billing ⌘B
Settings ⌘S

Press ⌘K or click the button.

Installation

php artisan ui:add command

Usage

@php
    $commands = [
        'Pages' => [
            ['label' => 'Profile', 'href' => '/profile', 'shortcut' => '⌘P'],
            ['label' => 'Billing', 'href' => '/billing'],
        ],
        'Actions' => [
            ['label' => 'New invoice', 'value' => 'new-invoice'],
            ['label' => 'Log out', 'value' => 'logout'],
        ],
    ];
@endphp

<x-ui.command :groups="$commands" />

{{-- Your own trigger, a different shortcut (empty disables it) --}}
<x-ui.command :groups="$commands" shortcut="j">
    <x-slot:trigger>
        <x-ui.button variant="outline">Open palette</x-ui.button>
    </x-slot:trigger>
</x-ui.command>

<script>
    // Items with a value dispatch command-select; it bubbles to window.
    window.addEventListener('command-select', (event) => {
        const { value, label } = event.detail;
        if (value === 'new-invoice') location.href = '/invoices/create';
    });
</script>

{{-- Livewire: listen with Alpine and call the component,
     e.g. x-on:command-select.window="$wire.run($event.detail.value)"
     on any element, or in a script block:
     window.addEventListener('command-select', e => $wire.run(e.detail.value)) --}}

Pass :groups as ['Heading' => [['label' => ..., 'href' => ...], ['label' => ..., 'value' => ...]]]; items with href navigate, items with value dispatch a bubbling command-select event (detail { value, label }) that reaches window. shortcut (default k, empty to disable) binds Cmd/Ctrl+key, an optional trigger slot replaces the default search button, and placeholder, search-placeholder, empty and label set the copy.

Props

Every prop with its default. Pass any of them as attributes, using : to bind a PHP value.

@props([
    'groups' => [],
    'shortcut' => 'k',
    'placeholder' => 'Search...',
    'searchPlaceholder' => 'Type a command or search...',
    'empty' => 'No results found.',
    'label' => 'Command palette',
])