Skip to content

Extras

CommandPalette

Bit.BlazorUI.ExtrasCommandMenuCmdkSpotlight

BitCommandPalette is an accessible, keyboard-first command palette: the Ctrl+K (Cmd+K on a Mac) box that fuzzy-searches every page, action and setting of an app and runs the one picked, with nested pages, prompts, multi-select, async sources, recents and global shortcuts. Matching, ranking and every decision run in C#; the browser only shows the native dialog and listens for keys.

Accessibility & diagnostics

What the palette does for assistive technology, how the dialog and the list are announced, the metrics and traces it emits, and fixes for the common problems.

Accessibility

The palette follows the WAI-ARIA combobox pattern with a grouped listbox. What that means for a page that restyles it or fills its templates:
  • The focus stays in the search box. Rows are never focused: the box points at the active row through aria-activedescendant, and a click on a row leaves the focus in the box. The active row's fill (--bit-CommandPalette-active-background) is therefore the only sign of where the keyboard is: keep it clearly distinct from the background. A template must not put a button, a link or any other focusable element in a row - it could never be reached with the keyboard.
  • The row's state is the palette's. The row element keeps aria-selected (or aria-checked on a multi-select page) and aria-disabled, and the reason a row is disabled is said in its subtitle. A switch's state and a pin are spoken by the default row in words (Strings.On, Strings.Off, Strings.Pinned), not only drawn; an ItemTemplate replaces them, so it says them itself, in visually hidden text, as the sample below does.
  • Groups are named by their headings, which are presentational: a GroupHeaderTemplate's text is what a screen reader says when it enters the group.
  • Live regions say the rest: polite regions, present before anything is announced in them, read the result count after every search, the page the palette moved to ("Theme. 3 results available"), the loading state and every toast, whatever the footer shows; errors are announced assertively. An inline palette announces only while it has the focus. A template therefore adds no aria-live or role="status" for these - except a LoadingTemplate, which replaces a state that had one.
  • Key caps are hidden from screen readers and the shortcut is spoken in words: draw shortcuts with BitCommandPaletteShortcutHint rather than bare <kbd>s, or hide yours.
  • The pointer moves the active row only once it actually moves, so a list scrolling under a resting mouse does not steal the keyboard's place. DisablePointerSelection stops hovering from moving it at all - only the keys and a click do - as in the palette below.
  • Matched characters keep the text's own color on their tint: a muted color on the tint would fall below 4.5:1. Keep that when restyling [data-bit-cpl="mark"].
  • The buttons (back, breadcrumbs, close, retry) are at least 24px, and their names hold what they show: the close button is "Close, Esc", and the trigger's name starts with its visible label (WCAG 2.5.3, label in name).

Open the inboxG then I
Archive all mail
Export the mailboxRequires the Pro plan
Notifications On
Theme

Accessibility of the dialog and the list

The palette follows the WAI-ARIA patterns for a modal dialog and a combobox with a grouped listbox, so it works with the keyboard alone and with screen readers, without any setup.
  • The modal palette is a native modal dialog element: it sits in the top layer, traps the focus, makes the page behind it inert, holds the page's scroll still, and gives the focus back to whatever had it when it closes.
  • The focus stays in the search input, which is a combobox controlling a listbox, and aria-activedescendant points at the active option, so screen readers follow the selection without the focus moving.
  • A single-select list marks its active option aria-selected; a multi-select page adds aria-multiselectable and marks its checked options aria-checked and nothing else, so each list has one state.
  • Each group is a role="group" named by its heading, so screen readers say which group an option is in, and the listbox owns only options and groups.
  • The list is a listbox only while it lists something; the empty, loading and error states are statuses and alerts instead, and the combobox's aria-expanded follows.
  • On a prompt the input is a plain text field named by the prompt's question.
  • In a virtualized list, where rows cannot be wrapped in their groups, each option is described by its heading and carries aria-posinset and aria-setsize.
  • Polite live regions, present before anything is announced in them, say the result count after every search, the page the palette moved to, loading, and every toast; errors are announced assertively, and the list is aria-busy while it loads.
  • A toggle's state and a pinned command are spoken ("On", "Off", "Pinned"), not only drawn.
  • A shortcut hint has an accessible name in words ("Ctrl+K", "G then S") while its key caps are hidden from screen readers, and the trigger declares aria-keyshortcuts.
  • Disabled commands are aria-disabled and say why, and group headings are not read as options.
  • Clicking a row leaves the focus in the input.
  • Pointer hover moves the selection only once the pointer actually moves, so a list scrolling under a resting mouse does not steal the keyboard's selection; DisablePointerSelection turns hover off completely.
  • The close button's accessible name holds its visible "Esc", and the trigger's name starts with its visible label (WCAG 2.5.3, label in name), as the Trigger section shows; the buttons are at least 24 pixels.
  • Animations follow BlazorUI's motion tokens, which collapse under prefers-reduced-motion.

Open the palette with the trigger below and a screen reader on: the result count, the active option and its group are announced as you type and move.

Diagnostics

The palette reports what it does through System.Diagnostics, so OpenTelemetry, Bit.Belemetry or any MeterListener picks it up - and it records nothing while nobody listens. Its meter and its activity source are both named Bit.BlazorUI.CommandPalette, available as BitCommandPaletteDiagnostics.MeterName and BitCommandPaletteDiagnostics.ActivitySourceName.
  • The bit.command_palette.command.executions counter (unit {execution}) counts the commands the palette ran, refused, or saw fail or be cancelled, tagged with bit.command_palette.command.kind, bit.command_palette.trigger (palette, shortcut or programmatic) and bit.command_palette.outcome (succeeded, failed, cancelled or refused).
  • The bit.command_palette.command.duration histogram (in seconds) records how long handlers took, with the same tags; a refusal ran nothing and has no duration.
  • The bit.command_palette.source.duration histogram (in seconds) records how long async sources took, tagged with bit.command_palette.source.name and bit.command_palette.outcome (succeeded, failed or timed_out); a search the palette abandoned is not recorded.
  • The bit.command_palette.search.duration histogram (in seconds) records how long matching and ranking the in-memory commands took for a query, with no tags.
  • Every handler runs inside a bit.command_palette.command activity, so the HttpClient calls it makes are its children, tagged with the kind, the trigger, the outcome and the command's id.
  • A failure sets the activity's status to an error and records the exception's type, never its message, which can quote what the user typed.
  • Every source search runs inside a bit.command_palette.source activity.
  • The palette's own rows (pin, forget, retry, "Show more") are neither counted nor traced.
  • Metrics never carry ids, and queries, prompt values, titles and selections are never recorded.
  • Set options.RecordCommandIdsInTraces to false when command ids embed personal data (person:[email protected]); it also keeps a command's id and title out of the log entries about running it, which read "(hidden)" instead.
  • On WebAssembly, metrics need the System.Diagnostics.Metrics feature switch (MetricsSupport), which the SDK turns off by default and Bit.Belemetry turns back on.

Every command run in the samples on this page is counted and traced under Bit.BlazorUI.CommandPalette when the app has a listener.

Troubleshooting

Most problems come from the setup; the palette also logs a warning or an entry for most of what it refuses to do, so the app's log is the first place to look.
  • When Ctrl+K does nothing, the palette is not interactive because it is in a statically rendered layout; also check that bit.blazorui.extras.js is linked and that no other script calls preventDefault on the key first.
  • When options from Program.cs (a toggle shortcut, the group order, commands added through options.Commands) stop working once the page turns interactive, the services are registered in only one project of a Blazor Web App and the palette in the other runs on the default options; it logs a warning saying the services are not registered. Call AddBitBlazorUIExtrasServices in both projects, through one shared method.
  • When the palette opens unstyled, the bit.blazorui.extras.css link is missing from the host page.
  • When a toggle shows its old state, remember that commands are immutable: register a new command with the same id, call Update on the service, or give BitCommandPaletteCommands a new list.
  • When recents forget a command whose title changed, its id was derived from the title; set an explicit Id.
  • When a page's commands are still listed after leaving it, dispose the handle Register returned, or register them with BitCommandPaletteCommands.
  • When a global shortcut does not fire in a text box, that is deliberate for plain keys; use a chord with a modifier, or set SuppressShortcutsInEditableElements to false.
  • When two palettes open at once, there is more than one modal palette in a scope; keep one, since every instance answers the same service, and use Inline for a palette that is part of a page.
  • When a command does nothing, or the wrong one runs, look at the app's log: the palette warns about duplicate ids, about shortcuts several commands claim or the toggle takes, and about links it refused, and it logs every failed command and page.
  • When a command does nothing and the footer says "You can’t run …", a guard refused it; the log has an information entry naming the command and what started it, and IBitCommandPaletteService.CommandRefused reports it to code.
  • When a command's shortcut works only after opening the palette, its VisibleWhen changed while the palette was closed; call Refresh() on the service after the state it reads changes.
  • When commands passed to the Commands parameter do not update, remember that the palette re-reads the parameter only when it gets a new collection; assign a new list, or call Refresh() after changing the same one.

The palette on this page is set up as the Getting started section shows; compare your app's setup with it first.

Feedback

Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.