Skip to content
Overlay CommandPalette

CommandPalette

A searchable list of commands, filtered in the browser as you type.

On this page

Examples

Inline

New fileCreate an empty fileN
New folderCreate a folder
Open settings
Profile
BillingInvoices and payment methods
Documentation
Delete account

Last command: none

Razor
<div class="flex w-full max-w-lg flex-col items-center gap-3">
    <div class="w-full overflow-hidden rounded-[calc(var(--klyroo-radius)*2)] border border-(--klyroo-border) bg-(--klyroo-bg-overlay)">
        <KlyCommandPalette Groups="Groups" OnSelect="item => _last = item.Label" Placeholder="Type a command or search..." data-testid="palette" />
    </div>
    <p class="text-sm text-(--klyroo-text-muted)" data-testid="palette-state">Last command: @(_last ?? "none")</p>
</div>

@code {
    private string? _last;

    private static readonly KlyCommandGroup[] Groups =
    [
        new("Suggestions",
        [
            new() { Label = "New file", Description = "Create an empty file", Shortcut = "N", Keywords = "create add" },
            new() { Label = "New folder", Description = "Create a folder", Keywords = "create directory" },
            new() { Label = "Open settings", Keywords = "preferences configuration" },
        ]),
        new("Account",
        [
            new() { Label = "Profile" },
            new() { Label = "Billing", Description = "Invoices and payment methods" },
            new() { Label = "Documentation", Href = "/docs", Keywords = "help guide" },
            new() { Label = "Delete account", Disabled = true },
        ]),
    ];
}

In a modal with Ctrl+K

data-kly-hotkey opens the modal from the keyboard, without .NET.

Go to dashboard
Go to settings
Switch theme
Sign out

Last command: none

Razor
<div class="flex flex-col items-center gap-3">
    <KlyModal AriaLabel="Command palette" Close="false" Ui="@(new ModalUi { Body = "p-0 sm:p-0" })">
        <ChildContent>
            <KlyButton Label="Search" Color="KlyColor.Neutral" Variant="ButtonVariant.Outline" data-kly-hotkey="mod+k" data-testid="palette-modal-trigger">
                <TrailingIcon><kbd class="text-xs">Ctrl K</kbd></TrailingIcon>
            </KlyButton>
        </ChildContent>
        <Body>
            <KlyCommandPalette Groups="Groups" CloseOnSelect OnSelect="item => _last = item.Label" Placeholder="Type a command or search..." />
        </Body>
    </KlyModal>
    <p class="text-sm text-(--klyroo-text-muted)" data-testid="palette-modal-state">Last command: @(_last ?? "none")</p>
</div>

@code {
    private string? _last;

    private static readonly KlyCommandGroup[] Groups =
    [
        new(null,
        [
            new() { Label = "Go to dashboard", Keywords = "home" },
            new() { Label = "Go to settings", Keywords = "preferences" },
            new() { Label = "Switch theme", Keywords = "dark light color mode" },
            new() { Label = "Sign out", Keywords = "logout" },
        ]),
    ];
}

Counts

Count shows a number at the end of the row, before the shortcut. The search does not read it.

Inbox, 12G I
Starred, 3
Archive, 1,840
Razor
<div class="flex w-full max-w-lg flex-col items-center gap-3">
    <div class="w-full overflow-hidden rounded-[calc(var(--klyroo-radius)*2)] border border-(--klyroo-border) bg-(--klyroo-bg-overlay)">
        <KlyCommandPalette Groups="Groups" Label="Go to a mailbox" Placeholder="Go to a mailbox..." data-testid="count-palette" />
    </div>
</div>

@code {
    // Count sits at the end of the row, before the shortcut; the search does not read it.
    private static readonly KlyCommandGroup[] Groups =
    [
        new("Mailboxes",
        [
            new() { Label = "Inbox", Count = 12, Shortcut = "G I" },
            new() { Label = "Starred", Count = 3 },
            new() { Label = "Archive", Count = 1840 },
        ]),
    ];
}

API

KlyCommandPalette

Searchable list of commands in a dialog, filtered in the browser as the user types and operated with the keyboard.

Parameters

Name Type Default Description
Class string Classes added to the root element, merged last so they win over the theme.
CloseOnSelect bool false Makes activating a command close the enclosing KlyModal , KlyDrawer or KlySlideover without a round trip.
Groups (required) IReadOnlyList<KlyCommandGroup> The commands, in groups. A group without a label has no heading.
Label string Accessible name of the search field and the list. Defaults to the built-in text.
Placeholder string Hint of the search field. Defaults to the built-in text.
Ui CommandPaletteUi Per-instance class overrides of the slots of the command palette, see CommandPaletteUi . They are merged after the theme and the Class parameter wins on the root slot.

Events

Name Type Description
OnSelect EventCallback<KlyCommandItem> Called with the activated command. Link commands navigate as well.

Ui slots

Ui takes a CommandPaletteUi with one class string per slot, merged after the theme.

Slot Styles
Root Classes merged into the root slot of KlyCommandPalette , KlyContentSearch and KlyDashboardSearch , after the theme and the app configuration.
InputWrapper Classes merged into the inputWrapper slot of KlyCommandPalette , KlyContentSearch and KlyDashboardSearch , after the theme and the app configuration.
InputIcon Classes merged into the inputIcon slot of KlyCommandPalette , KlyContentSearch and KlyDashboardSearch , after the theme and the app configuration.
Input Classes merged into the input slot of KlyCommandPalette , KlyContentSearch and KlyDashboardSearch , after the theme and the app configuration.
Listbox Classes merged into the listbox slot of KlyCommandPalette , KlyContentSearch and KlyDashboardSearch , after the theme and the app configuration.
Group Classes merged into the group slot of KlyCommandPalette , KlyContentSearch and KlyDashboardSearch , after the theme and the app configuration.
GroupLabel Classes merged into the groupLabel slot of KlyCommandPalette , KlyContentSearch and KlyDashboardSearch , after the theme and the app configuration.
Item Classes merged into the item slot of KlyCommandPalette , KlyContentSearch and KlyDashboardSearch , after the theme and the app configuration.
ItemIcon Classes merged into the itemIcon slot of KlyCommandPalette , KlyContentSearch and KlyDashboardSearch , after the theme and the app configuration.
ItemWrapper Classes merged into the itemWrapper slot of KlyCommandPalette , KlyContentSearch and KlyDashboardSearch , after the theme and the app configuration.
ItemLabel Classes merged into the itemLabel slot of KlyCommandPalette , KlyContentSearch and KlyDashboardSearch , after the theme and the app configuration.
ItemDescription Classes merged into the itemDescription slot of KlyCommandPalette , KlyContentSearch and KlyDashboardSearch , after the theme and the app configuration.
ItemShortcut Classes merged into the itemShortcut slot of KlyCommandPalette , KlyContentSearch and KlyDashboardSearch , after the theme and the app configuration.
ItemCount Classes merged into the itemCount slot of KlyCommandPalette , KlyContentSearch and KlyDashboardSearch , after the theme and the app configuration.
Empty Classes merged into the empty slot of KlyCommandPalette , KlyContentSearch and KlyDashboardSearch , after the theme and the app configuration.
Status Classes merged into the status slot of KlyCommandPalette , KlyContentSearch and KlyDashboardSearch , after the theme and the app configuration.