Command Palette 命令面板 Command Palette web

标本可交互 —— 点点看。Specimen is live — try it.

Anatomy — every part, named解剖 —— 每个部件的名字

  1. 1 Command input命令输入框 CommandInput

    “The search field at the top of the ⌘K menu” is the command input.

    「⌘K 菜单顶部的搜索框」就是命令输入框。

    Prompt fragmentPrompt 片段

    the shadcn/ui CommandInput at the top of the command palette, filtering commands as the user types

    命令面板顶部的 shadcn/ui CommandInput,随用户输入过滤命令

  2. 2 Command group命令分组 CommandGroup

    “The labeled section grouping similar actions” is a command group.

    「把同类操作归在一起、带小标题的分区」就是命令分组。

    Prompt fragmentPrompt 片段

    a shadcn/ui CommandGroup with a quiet heading above a related set of command items

    一个 shadcn/ui CommandGroup,低调的小标题下面是一组相关命令项

  3. 3 Active command活动命令 CommandItem

    “The result with the highlight that Enter will run” is the active command.

    「高亮显示、按 Enter 就会执行的那条结果」就是活动命令。

    Prompt fragmentPrompt 片段

    the active shadcn/ui CommandItem with a full-row selection highlight showing what Enter will execute

    活动的 shadcn/ui CommandItem,整行选中高亮,表明 Enter 将执行什么

  4. 4 Command shortcut命令快捷键 CommandShortcut

    “The ⌘ letters aligned on the right of an action” are the command shortcut.

    「操作项右边对齐的那几个 ⌘ 字母」就是命令快捷键。

    Prompt fragmentPrompt 片段

    the shadcn/ui CommandShortcut aligned at the trailing edge of its command item

    shadcn/ui CommandShortcut,对齐在命令项的末尾边缘

Prompt — paste into your agentPrompt —— 直接粘贴给你的代理

Add a Command Palette using the shadcn/ui Command component inside a role="dialog", opened by ⌘K or Ctrl+K. Filter actions as the user types, support arrow-key selection and Enter, and restore focus to the invoking control on dismissal.

用 shadcn/ui 的 Command 组件加一个命令面板,放在 role="dialog" 里,用 ⌘K 或 Ctrl+K 打开。随用户输入过滤操作,支持方向键选择和 Enter 执行,关闭后把焦点还给触发它的控件。

Debug prompt — when it misbehaves调试 Prompt —— 当它不听话时

Debug my command palette (cmdk, Dialog + Command). Rule out: the cmd/ctrl-K listener attached to the wrong scope or eaten by the browser; the filter state persisting from the previous open — reset on open; focus escaping the dialog because the trap ignores portaled content; keydown firing during IME composition (check isComposing); the palette rendered under a higher stacking context. The symptom:

调试我的命令面板(cmdk、Dialog + Command)。排查:⌘/Ctrl+K 监听器挂错了作用域,或被浏览器吃掉;上次打开时的过滤状态还留着——打开时要重置;焦点逃出 dialog,因为焦点陷阱忽略了 portal 渲染的内容;IME 输入法组词期间触发了 keydown(检查 isComposing);面板被更高的层叠上下文压在下面。症状:

In code代码里叫什么

Framework框架Symbol符号Note说明
shadcn/ui Command
ARIA role="dialog"
ARIA role="combobox"
Radix Dialog

See also相关词条