ShellUI Logo
ShellUI

Command Palette

Keyboard-launched command menu (Ctrl+K or Cmd+K)

CommandPalette opens a searchable command menu with a keyboard shortcut, Ctrl+K or ⌘K by default. Commands can be grouped and can show a description and a shortcut hint.

Installation

shellui add command-palette

The CLI also installs command, dialog, the CommandItem model and shellui.js, and adds the models @using to _Imports.razor. With the NuGet package, add @using ShellUI.Components.Models.

Usage

@inject NavigationManager Nav

<CommandPalette Commands="_commands" />

@code {
    private List<CommandItem> _commands = new();

    protected override void OnInitialized()
    {
        _commands = new()
        {
            new() { Title = "Dashboard", Group = "Navigation", Action = () => Go("/") },
            new() { Title = "Settings", Group = "Navigation", Shortcut = "G S", Action = () => Go("/settings") },
            new() { Title = "New project", Description = "Create an empty project", Group = "Actions" },
        };
    }

    private Task Go(string url)
    {
        Nav.NavigateTo(url);
        return Task.CompletedTask;
    }
}

Custom shortcut

@* Ctrl+Shift+P, like VS Code *@
<CommandPalette Commands="_commands" HotkeyChar="p" UseMeta="false" UseShift="true" />

UseCtrl and UseMeta are alternatives: with both on (the default), either Ctrl or ⌘ opens the palette.

CommandItem

PropertyTypeDefaultDescription
Titlestring""Command text
Descriptionstring?nullSecondary text
Iconstring?nullIcon markup
Shortcutstring?nullShortcut hint shown on the right
Groupstring?nullGroup heading
ActionFunc<Task>?nullRuns when the command is chosen

API Reference

PropertyTypeDefaultDescription
CommandsList<CommandItem>empty listThe commands
CommandSelectedEventCallback<CommandItem>—Raised when a command is chosen
Placeholderstring"Type a command or search..."Search box placeholder
HotkeyCharstring"k"Key that opens the palette
UseCtrlbooltrueCtrl + key opens it
UseMetabooltrue⌘ + key opens it
UseShiftboolfalseAlso require Shift
UseAltboolfalseAlso require Alt

On this page