Skip to content
synccn

Command Center

New

Command palette with nested pages, recent commands, async providers and match highlighting.

Actions

Invite teammate⌘I
New document⌘N
Change theme

Settings

Profile
Billing
Notifications
General
↑↓ move↵ run

Or as an overlay: press ⌘K or

Installation

$ pnpm dlx shadcn@latest add @synccn/command-center

First time in this project? Connect synccn with one command.

Usage

import { CommandCenter, CommandCenterDialog } from "@/components/ui/command-center";<CommandCenterDialog open={open} onOpenChange={setOpen} providers={providers} />

API reference

Generated from the component's TypeScript types, so it always matches the code.

CommandCenter

Command palette engine: grouped results from several providers (fixed or async), nested pages, recent commands, match highlighting and full keyboard control. Use it inline, or in CommandCenterDialog for a ⌘K overlay.

  • providersrequired
    CommandProvider[]

    Where commands come from.

  • onSelect
    (item: CommandItem) => void

    Called after any command is chosen (except opening a sub-page).

  • placeholder
    string

    Default "Type a command or search…"

    Search box placeholder.

  • recentsKey
    string

    Remember recently used commands under this localStorage key.

  • maxRecents
    number

    Default 5

    How many recent commands to show.

  • autoFocus
    boolean

    Default true

    Focus the search box on mount.

  • className
    string

    Extra classes for the root element.

CommandCenterDialog

CommandCenter in a centred overlay, with ⌘K to open, Escape to close and focus kept inside.

  • openrequired
    boolean

    Controlled open state.

  • onOpenChangerequired
    (open: boolean) => void

    Called to open or close.

  • hotkey
    boolean

    Default true

    Open with ⌘K / Ctrl+K. Default true.

  • providersrequired
    CommandProvider[]

    Where commands come from.

  • onSelect
    (item: CommandItem) => void

    Called after any command is chosen (except opening a sub-page).

  • placeholder
    string

    Search box placeholder.

  • recentsKey
    string

    Remember recently used commands under this localStorage key.

  • maxRecents
    number

    How many recent commands to show.

  • autoFocus
    boolean

    Focus the search box on mount.

  • className
    string

    Extra classes for the root element.

Dependencies

Read from the component's imports when the site builds. The CLI installs all of these for you.

Components

Helpers

  • lib/hooksuseFocusTrap (keeps focus inside while open), useIsClient (renders portals only in the browser), useLockScroll (locks page scroll while open), usePresence (animates in and out)
  • lib/utilscn (merges class names)

npm packages

Keyboard

  • ↓or↑Move through results
  • EnterRun a command or open its page
  • BackspaceGo back a page when the search is empty
  • EscGo back a page, or close the dialog
  • Ctrl+Kor⌘KOpen or close the dialog

Accessibility

  • The search box is a combobox that points at the active option with aria-activedescendant.
  • Results are a listbox with options in labelled groups.
  • The dialog traps focus, locks page scroll and returns focus when closed.

From the source

Read from this component's code when the site builds, so it can't drift.

  • ARIA roles: combobox, dialog, group, listbox, option
  • ARIA attributes: aria-activedescendant, aria-autocomplete, aria-controls, aria-expanded, aria-label, aria-modal, aria-selected
  • Keys handled: ArrowUp, ArrowDown, Home, End, Enter, Escape, Backspace
  • Keeps keyboard focus inside while open, and returns it when closed
  • Stops the page behind from scrolling while open
  • Shows a visible focus ring for keyboard users