suiss/ui · Pattern
Command Palette
A searchable command menu that opens in a dialog on desktop and a drawer on mobile.
Command Palette is an open-source pattern from suiss/ui for React. The @esuiss/ui CLI copies its source into your project, so you own the code.
CommandPalette hosts a Command list inside a Dialog on desktop, positioned in the upper third of the viewport, and inside a bottom Drawer with a swipe handle below the 48rem breakpoint. A global keyboard shortcut toggles it: Cmd+K on macOS and Ctrl+K elsewhere by default.
Use it for app-wide search and quick actions.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Usage
Composition
Use the following composition to build a CommandPalette:
Examples
With close button
Set showCloseButton to show an icon close button in the corner of the popup. On mobile the input gains end padding so it does not run under the button.
With close label
Set closeLabel together with showCloseButton to replace the close icon with text, here Cancel.
Floating
Set floating to inset the mobile drawer from the screen edges with fully rounded corners.
Accessibility
- The popup is a
dialognamed bytitleand described bydescription. - Opening the palette focuses the search input, and the first enabled option is selected.
- Arrow keys move between options and skip disabled ones; typing filters the list.
Escapecloses the palette and returns focus to the trigger.
API Reference
CommandPalette
The root that renders a Dialog on desktop and a Drawer on mobile and registers the hotkey.
| Prop | Type | Default |
|---|---|---|
open | boolean | - |
defaultOpen | boolean | false |
onOpenChange | (open: boolean) => void | - |
hotkey | string | false | "k" |
floating | boolean | - |
children | React.ReactNode | - |
The palette can be controlled with open and onOpenChange or uncontrolled with defaultOpen; the hotkey and the trigger update the same state, and onOpenChange also fires for the hotkey. hotkey is the letter that toggles the palette together with Cmd on macOS or Ctrl elsewhere. Set it to another letter to change the shortcut, or to false to disable it.
CommandPaletteTrigger
The button that opens the palette.
| Prop | Type | Default |
|---|---|---|
render | React.ReactElement | - |
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
Also accepts the props of DialogTrigger.
Also accepts className, children, id and aria-label.
Use render to replace the default button with your own element, for example a Button with a Kbd hint.
Set asChild to render your own button in place of the default one, for example a Button with a Kbd hint.
CommandPaletteContent
The popup that wraps a Command with a visually hidden title and description.
| Prop | Type | Default |
|---|---|---|
title | string | "Command Palette" |
description | string | "Search for a command to run..." |
showCloseButton | boolean | false |
closeLabel | string | - |
Also accepts the props of React.ComponentProps<typeof Command>.
Fill it with CommandInput, CommandList, CommandGroup, CommandItem and the other Command parts. title and description name and describe the dialog and are rendered visually hidden. Remaining props, including className, pass through to the inner Command, not the dialog or drawer. On mobile the list is capped at 60dvh.
Each part sets a data-slot, such as command-palette or command-palette-content, for styling.