Ir al contenido
Español

Cómo funciona

Matching tries a contiguous run first, then the letters in order (at most three pieces), and falls back to keywords. Focus stays in the field; a single highlight element glides to the active option with transform and height, and keeps it in view by adjusting the list's own scroll, never the page's.

Úsalo para

  • Apps with many pages or actions where power users want to jump by keyboard.
  • A single entry point for search, navigation and commands.

Busca otra opción cuando

  • Searching large remote data with filters: use a full search page.
  • Touch-first apps without a keyboard: a visible menu is easier.

Uso

import { useState } from 'react'
import { CommandPalette } from './CommandPalette.jsx'

export function AppSearch() {
  const [open, setOpen] = useState(false)
  return (
    <CommandPalette
      open={open}
      onOpenChange={setOpen}
      recent={[{ id: 'roadmap', label: 'Q4 roadmap', hint: 'Projects' }]}
      groups={[
        { id: 'pages', label: 'Pages', items: [{ id: 'guide', label: 'Onboarding guide', keywords: ['welcome'] }] },
        { id: 'actions', label: 'Actions', items: [{ id: 'new', label: 'New page', shortcut: ['⌘', 'N'] }] },
      ]}
      onSelect={(item) => console.log(item.id)}
    />
  )
}

Propiedades

PropiedadTipoPor defectoQué hace
openboolean—Whether the palette is shown.
onOpenChange(open: boolean) => void—Called on the hotkey, Escape, a click outside or after a choice.
groups{ id, label, items: { id, label, hint?, icon?, shortcut?: string[], keywords?: string[], disabled? }[] }[]—Grouped commands; empty groups are hidden while searching.
recentItem[]—Shown as the first group while the field is empty.
onSelect(item) => void—Called with the chosen item.
labelsobject—Replaces built-in text: placeholder, dialog, recent, empty ({query} is replaced), emptyHint, navigate, open, close.
hotkeystring | false'k'Letter that toggles the palette with ⌘ or Ctrl; false turns it off.
containedbooleanfalseFill the nearest positioned ancestor instead of the viewport.
footerbooleantrueShow the keyboard hint bar.

Accesibilidad

  • role dialog with aria-modal; the field is a combobox that controls a listbox, with grouped role option rows.
  • aria-activedescendant announces the active option while focus stays in the field.
  • Up and Down (or Ctrl+N and Ctrl+P) move, Home and End jump, Enter chooses, Escape clears the query and then closes; Tab stays inside.
  • Focus moves to the field on open and returns to the previous element on close.
  • The empty state is a role status message.
  • With reduced motion the panel only fades and the highlight jumps.

Movimiento

Panel enters 260ms ease-out from 6px above at 0.98 scale, leaves in 140ms; the highlight glides 200ms ease-out; the enter glyph slides in 4px.

Añádelo a tu proyecto

Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.

CommandPalette.jsxcommand-palette.csstokens.cssREADME.md

Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

Navegación
Barra dock viene con Pro. La vista previa aparece al desbloquearlo.