Skip to content
GitHub11 stars

Command menu for search and quick actions.

<Command Class="max-w-sm rounded-lg border">
    <CommandInput placeholder="Type a command or search..." />
    <CommandList>

About

The Command component is a port of cmdk by Dip: the same fuzzy filtering, ranking and keyboard navigation, with no JavaScript dependency.

Installation

dnx Blazix.Cli add command

Usage

<Command Class="max-w-sm rounded-lg border">
    <CommandInput placeholder="Type a command or search..." />
    <CommandList>
        <CommandEmpty>No results found.</CommandEmpty>
        <CommandGroup Heading="Suggestions">
            <CommandItem>Calendar</CommandItem>
            <CommandItem>Search Emoji</CommandItem>
            <CommandItem>Calculator</CommandItem>
        </CommandGroup>
        <CommandSeparator />
        <CommandGroup Heading="Settings">
            <CommandItem>Profile</CommandItem>
            <CommandItem>Billing</CommandItem>
            <CommandItem>Settings</CommandItem>
        </CommandGroup>
    </CommandList>
</Command>

To open the menu with ⌘K (Ctrl+K on Windows and Linux), put it in a CommandDialog and toggle it with a KeyboardShortcut. OnSelect passes the selected item's value: close the dialog, then run the command it names.

<KeyboardShortcut Key="k" OnPressed="() => _open = !_open" />
<CommandDialog @bind-Open="_open">
    <Command>
        <CommandInput placeholder="Type a command or search..." />
        <CommandList>
            <CommandEmpty>No results found.</CommandEmpty>
            <CommandGroup Heading="Suggestions">
                <CommandItem OnSelect="RunCommand">Calendar</CommandItem>
                <CommandItem OnSelect="RunCommand">Search Emoji</CommandItem>
                <CommandItem OnSelect="RunCommand">Calculator</CommandItem>
            </CommandGroup>
        </CommandList>
    </Command>
</CommandDialog>

@code {
    private bool _open;

    private void RunCommand(string value)
    {
        _open = false;
    }
}

Composition

Use the following composition to build a Command:

Command
├── CommandInput
└── CommandList
    ├── CommandEmpty
    ├── CommandGroup
    │   ├── CommandItem
    │   └── CommandItem
    ├── CommandSeparator
    └── CommandGroup
        ├── CommandItem
        └── CommandItem

Basic

A simple command menu in a dialog.

Command Palette

Search for a command to run...

<div class="flex flex-col gap-4">
    <Button Variant="ButtonVariant.Outline" Class="w-fit" @onclick="() => _open = true">Open Menu</Button>
    <CommandDialog @bind-Open="_open">

Shortcuts

Command Palette

Search for a command to run...

<div class="flex flex-col gap-4">
    <Button Variant="ButtonVariant.Outline" Class="w-fit" @onclick="() => _open = true">Open Menu</Button>
    <CommandDialog @bind-Open="_open">

Groups

A command menu with groups, icons and separators.

Command Palette

Search for a command to run...

<div class="flex flex-col gap-4">
    <Button Variant="ButtonVariant.Outline" Class="w-fit" @onclick="() => _open = true">Open Menu</Button>
    <CommandDialog @bind-Open="_open">

Scrollable

Scrollable command menu with multiple items.

Command Palette

Search for a command to run...

<div class="flex flex-col gap-4">
    <Button Variant="ButtonVariant.Outline" Class="w-fit" @onclick="() => _open = true">Open Menu</Button>
    <CommandDialog @bind-Open="_open">

RTL

To enable RTL support in Blazix, see the RTL configuration guide.

Translated with AI for the demo, so it may have mistakes.

<Command Class="max-w-sm rounded-lg border">
    <CommandInput placeholder="@T.Placeholder" />
    <CommandList>

API Reference

Command

ParameterTypeDefault
Label string? -
ShouldFilter bool true
Filter Func<string, string, IReadOnlyList<string>, double>? -
Value string? -
ValueChanged EventCallback<string> -
Loop bool false
DisablePointerSelection bool false
VimBindings bool true
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

CommandDialog

ParameterTypeDefault
Title string "Command Palette"
Description string "Search for a command to run..."
ShowCloseButton bool false
Open bool false
OpenChanged EventCallback<bool> -
OnOpenChange EventCallback<OpenChangeEventArgs> -
OnOpenChangeComplete EventCallback<bool> -
Modal PopupModal PopupModal.True
DisablePointerDismissal bool false
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

CommandEmpty

ParameterTypeDefault
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

CommandGroup

ParameterTypeDefault
Heading string? -
ForceMount bool false
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

CommandInput

ParameterTypeDefault
Value string? -
ValueChanged EventCallback<string> -
Class string? -

Other attributes are passed to the element it renders.

CommandItem

ParameterTypeDefault
Value string? -
Keywords IReadOnlyList<string>? -
Disabled bool false
OnSelect EventCallback<string> -
ForceMount bool false
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

CommandList

ParameterTypeDefault
Label string "Suggestions"
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

CommandSeparator

ParameterTypeDefault
AlwaysRender bool false
Class string? -

Other attributes are passed to the element it renders.

CommandShortcut

ParameterTypeDefault
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.