Command
用于搜索过滤和快速执行操作的命令面板组件,支持内联与弹窗组合。
支持实时搜索过滤和键盘导航的命令面板,点击或按下 Enter 即可发出 execute 事件由应用执行操作。本页示例采用 Shadcn Rhea 风格。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<shadcn-style-scope id="command-scope" class="contents">
<div
class="w-full max-w-sm rounded-[var(--pui-radius-3xl)] border border-border bg-popover shadow-md"
>
<shadcn-command-root id="command-root">
<shadcn-command-input-wrapper>
<shadcn-input-shell id="command-shell">
<shadcn-command-input
id="command-input"
></shadcn-command-input>
</shadcn-input-shell>
</shadcn-command-input-wrapper>
<shadcn-command-content>
<div
class="px-2 py-1.5 text-xs font-medium text-muted-foreground"
aria-hidden="true"
>
Suggestions
</div>
<shadcn-command-item data-cmd="calendar">
Calendar
</shadcn-command-item>
<shadcn-command-item data-cmd="search-emoji">
Search Emoji
</shadcn-command-item>
<shadcn-command-item data-cmd="calculator">
Calculator
</shadcn-command-item>
<div class="my-1 h-px bg-border" role="separator"></div>
<div
class="px-2 py-1.5 text-xs font-medium text-muted-foreground"
aria-hidden="true"
>
Settings
</div>
<shadcn-command-item data-cmd="profile">
<span>Profile</span>
<span
class="ml-auto font-mono text-xs text-muted-foreground"
>
⌘P
</span>
</shadcn-command-item>
<shadcn-command-item data-cmd="billing">
<span>Billing</span>
<span
class="ml-auto font-mono text-xs text-muted-foreground"
>
⌘B
</span>
</shadcn-command-item>
<shadcn-command-item data-cmd="settings">
<span>Settings</span>
<span
class="ml-auto font-mono text-xs text-muted-foreground"
>
⌘S
</span>
</shadcn-command-item>
<shadcn-command-empty>
No results found.
</shadcn-command-empty>
</shadcn-command-content>
</shadcn-command-root>
</div>
</shadcn-style-scope>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
setElementProps(document.querySelector('#command-scope'), {
styleProfile: 'rhea',
});
setElementProps(document.querySelector('#command-shell'), {
focusIndicator: 'none',
});
setElementProps(document.querySelector('#command-input'), {
placeholder: 'Type a command or search...',
a11yLabel: 'Type a command or search',
});
const root = document.querySelector('#command-root');
setElementProps(root, { a11yLabel: 'Command menu' });
root.addEventListener('execute', (event) =>
console.log('execute', event.detail)
);
</script>将于 0.3.0-rc.1 及后续版本中提供(@proto.ui/prototypes-shadcn/command)。
import { commandRoot, commandInputWrapper, commandInput, commandContent, commandItem, commandEmpty, commandDialogContent, commandDialogMask,} from '@proto.ui/prototypes-shadcn/command';import { inputShell } from '@proto.ui/prototypes-shadcn/input-shell';部件组合结构
Section titled “部件组合结构”CommandRoot├── CommandInputWrapper│ └── InputShell (focusIndicator="none")│ └── CommandInput└── CommandContent ├── CommandItem └── CommandEmpty- 内联默认展开:
defaultOpen默认为true,输入文本只会过滤候选列表而不会自动执行命令;点击或按Enter时通过execute事件通知应用层。 - 弹窗组合:可结合
DialogRoot、DialogTrigger、CommandDialogMask与CommandDialogContent构成命令弹窗,按当前styleProfile传入对应enterDuration/leaveDuration(Rhea 为100,New York 为200)。 - 过滤与键盘行为:按
textValue与keywords忽略大小写与重音匹配,设置filter={false}可接入外部过滤;方向键移动高亮项时焦点保留在输入框中,IME 组合输入期间不触发执行。
结合 Dialog 与 CommandDialogContent 构建居中浮层命令面板。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<shadcn-style-scope id="dialog-scope" class="contents">
<shadcn-dialog-root>
<shadcn-dialog-trigger>Open Menu</shadcn-dialog-trigger>
<shadcn-command-dialog-mask
id="cmd-mask"
></shadcn-command-dialog-mask>
<shadcn-command-dialog-content id="cmd-dialog">
<shadcn-dialog-title class="sr-only">
Command Palette
</shadcn-dialog-title>
<shadcn-dialog-description class="sr-only">
Search for a command to run.
</shadcn-dialog-description>
<shadcn-command-root id="cmd-root">
<shadcn-command-input-wrapper>
<shadcn-input-shell id="cmd-shell">
<shadcn-command-input
id="cmd-input"
></shadcn-command-input>
</shadcn-input-shell>
</shadcn-command-input-wrapper>
<shadcn-command-content>
<shadcn-command-item>Calendar</shadcn-command-item>
<shadcn-command-item>Search Emoji</shadcn-command-item>
<shadcn-command-item>Calculator</shadcn-command-item>
<shadcn-command-empty>
No results found.
</shadcn-command-empty>
</shadcn-command-content>
</shadcn-command-root>
</shadcn-command-dialog-content>
</shadcn-dialog-root>
</shadcn-style-scope>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
setElementProps(document.querySelector('#dialog-scope'), {
styleProfile: 'rhea',
});
setElementProps(document.querySelector('#cmd-mask'), {
enterDuration: 100,
leaveDuration: 100,
});
setElementProps(document.querySelector('#cmd-dialog'), {
enterDuration: 100,
leaveDuration: 100,
});
setElementProps(document.querySelector('#cmd-shell'), {
focusIndicator: 'none',
});
setElementProps(document.querySelector('#cmd-input'), {
placeholder: 'Type a command or search...',
});
</script>快捷键提示与关键词搜索
Section titled “快捷键提示与关键词搜索”在 CommandItem 中组合右侧快捷键标签,并通过 keywords 扩展匹配词。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<shadcn-style-scope id="shortcuts-scope" class="contents">
<div
class="w-full max-w-sm rounded-[var(--pui-radius-3xl)] border border-border bg-popover shadow-md"
>
<shadcn-command-root>
<shadcn-command-input-wrapper>
<shadcn-input-shell>
<shadcn-command-input></shadcn-command-input>
</shadcn-input-shell>
</shadcn-command-input-wrapper>
<shadcn-command-content>
<shadcn-command-item>
<span>Profile</span>
<span
class="ml-auto font-mono text-xs text-muted-foreground"
>
⌘P
</span>
</shadcn-command-item>
<shadcn-command-item>
<span>Billing</span>
<span
class="ml-auto font-mono text-xs text-muted-foreground"
>
⌘B
</span>
</shadcn-command-item>
<shadcn-command-item>
<span>Settings</span>
<span
class="ml-auto font-mono text-xs text-muted-foreground"
>
⌘S
</span>
</shadcn-command-item>
<shadcn-command-item>
<span>Keyboard Shortcuts</span>
<span
class="ml-auto font-mono text-xs text-muted-foreground"
>
⌘K
</span>
</shadcn-command-item>
<shadcn-command-empty>
No matching shortcuts.
</shadcn-command-empty>
</shadcn-command-content>
</shadcn-command-root>
</div>
</shadcn-style-scope>分组与禁用项
Section titled “分组与禁用项”使用语义分组标题、分隔线和 disabled 命令项组织复杂工作区命令。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<shadcn-style-scope id="command-scope" class="contents">
<div
class="w-full max-w-sm rounded-[var(--pui-radius-3xl)] border border-border bg-popover shadow-md"
>
<shadcn-command-root id="command-root">
<shadcn-command-input-wrapper>
<shadcn-input-shell id="command-shell">
<shadcn-command-input
id="command-input"
></shadcn-command-input>
</shadcn-input-shell>
</shadcn-command-input-wrapper>
<shadcn-command-content>
<div
class="px-2 py-1.5 text-xs font-medium text-muted-foreground"
aria-hidden="true"
>
Suggestions
</div>
<shadcn-command-item data-cmd="calendar">
Calendar
</shadcn-command-item>
<shadcn-command-item data-cmd="search-emoji">
Search Emoji
</shadcn-command-item>
<shadcn-command-item data-cmd="calculator">
Calculator
</shadcn-command-item>
<div class="my-1 h-px bg-border" role="separator"></div>
<div
class="px-2 py-1.5 text-xs font-medium text-muted-foreground"
aria-hidden="true"
>
Settings
</div>
<shadcn-command-item data-cmd="profile">
<span>Profile</span>
<span
class="ml-auto font-mono text-xs text-muted-foreground"
>
⌘P
</span>
</shadcn-command-item>
<shadcn-command-item data-cmd="billing">
<span>Billing</span>
<span
class="ml-auto font-mono text-xs text-muted-foreground"
>
⌘B
</span>
</shadcn-command-item>
<shadcn-command-item data-cmd="settings">
<span>Settings</span>
<span
class="ml-auto font-mono text-xs text-muted-foreground"
>
⌘S
</span>
</shadcn-command-item>
<shadcn-command-empty>
No results found.
</shadcn-command-empty>
</shadcn-command-content>
</shadcn-command-root>
</div>
</shadcn-style-scope>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
setElementProps(document.querySelector('#command-scope'), {
styleProfile: 'rhea',
});
setElementProps(document.querySelector('#command-shell'), {
focusIndicator: 'none',
});
setElementProps(document.querySelector('#command-input'), {
placeholder: 'Type a command or search...',
a11yLabel: 'Type a command or search',
});
const root = document.querySelector('#command-root');
setElementProps(root, { a11yLabel: 'Command menu' });
root.addEventListener('execute', (event) =>
console.log('execute', event.detail)
);
</script>可滚动长列表
Section titled “可滚动长列表”在限高列表容器内展示大量分组命令,支持滚轮与方向键浏览。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<shadcn-style-scope id="command-scope" class="contents">
<div
class="w-full max-w-sm rounded-[var(--pui-radius-3xl)] border border-border bg-popover shadow-md"
>
<shadcn-command-root id="command-root">
<shadcn-command-input-wrapper>
<shadcn-input-shell id="command-shell">
<shadcn-command-input
id="command-input"
></shadcn-command-input>
</shadcn-input-shell>
</shadcn-command-input-wrapper>
<shadcn-command-content>
<div
class="px-2 py-1.5 text-xs font-medium text-muted-foreground"
aria-hidden="true"
>
Suggestions
</div>
<shadcn-command-item data-cmd="calendar">
Calendar
</shadcn-command-item>
<shadcn-command-item data-cmd="search-emoji">
Search Emoji
</shadcn-command-item>
<shadcn-command-item data-cmd="calculator">
Calculator
</shadcn-command-item>
<div class="my-1 h-px bg-border" role="separator"></div>
<div
class="px-2 py-1.5 text-xs font-medium text-muted-foreground"
aria-hidden="true"
>
Settings
</div>
<shadcn-command-item data-cmd="profile">
<span>Profile</span>
<span
class="ml-auto font-mono text-xs text-muted-foreground"
>
⌘P
</span>
</shadcn-command-item>
<shadcn-command-item data-cmd="billing">
<span>Billing</span>
<span
class="ml-auto font-mono text-xs text-muted-foreground"
>
⌘B
</span>
</shadcn-command-item>
<shadcn-command-item data-cmd="settings">
<span>Settings</span>
<span
class="ml-auto font-mono text-xs text-muted-foreground"
>
⌘S
</span>
</shadcn-command-item>
<shadcn-command-empty>
No results found.
</shadcn-command-empty>
</shadcn-command-content>
</shadcn-command-root>
</div>
</shadcn-style-scope>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
setElementProps(document.querySelector('#command-scope'), {
styleProfile: 'rhea',
});
setElementProps(document.querySelector('#command-shell'), {
focusIndicator: 'none',
});
setElementProps(document.querySelector('#command-input'), {
placeholder: 'Type a command or search...',
a11yLabel: 'Type a command or search',
});
const root = document.querySelector('#command-root');
setElementProps(root, { a11yLabel: 'Command menu' });
root.addEventListener('execute', (event) =>
console.log('execute', event.detail)
);
</script>传入 value、inputValue 或 open 可独立切换为受控模式;styleProfile 可通过外层 shadcn-style-scope 或部件属性指定 9 套内置风格。
| 属性 | 类型 | 默认值 |
|---|---|---|
value | string | — |
defaultValue | string | '' |
inputValue | string | — |
defaultInputValue | string | '' |
open | boolean | — |
defaultOpen | boolean | true |
disabled | boolean | false |
readOnly | boolean | false |
filter | boolean | true |
loop | boolean | true |
a11yLabel | string | '' |
styleProfile | ShadcnStyleId | 'new-york-v4' |
presentation | 'default' 'menu' | 'default' |
其他部件与事件
Section titled “其他部件与事件”- InputWrapper:输入区外层容器,支持
styleProfile与presentation('default' | 'menu')。 - Input:
placeholder、a11yLabel、name均默认为''。 - Content:
side="bottom"、align="start"、sideOffset={4}、collisionPadding={8}。 - Item:
value、textValue、keywords均默认为'',disabled默认为false。 - Empty:无独立属性,根据可见匹配数量自动显隐。
- DialogContent / DialogMask:必填
enterDuration: number与leaveDuration: number;DialogContent另支持styleProfile与presentation。 - 事件:
Root触发execute、valueChange、inputValueChange与openChange。