示例
命令菜单
忠实重现的命令面板:对话框将焦点交给组合框,组合框的浮动筛选列表在输入框下方展开,而不是以内嵌命令列表的形式显示。
预览
Go to dashboard
Go to deployments
Go to billing
Create new project
Invite a teammate
Rotate API key
Toggle dark mode
Open documentation
Contact support
HTML
<bs:bsui-stack direction="row" gap="2" align="center">
<bs:bsui-dialog>
<bs:bsui-dialog-trigger trigger_label="Search documentation" trigger_variant="outline" />
<bs:bsui-dialog-backdrop />
<bs:bsui-dialog-popup>
<bs:bsui-dialog-content>
<bs:bsui-combobox name="command" placeholder="Type a command or search...">
<bs:bsui-combobox-input />
<bs:bsui-combobox-popup>
<bs:bsui-combobox-option value="dashboard" label="Go to dashboard" />
<bs:bsui-combobox-option value="deployments" label="Go to deployments" />
<bs:bsui-combobox-option value="billing" label="Go to billing" />
<bs:bsui-combobox-option value="new-project" label="Create new project" />
<bs:bsui-combobox-option value="invite" label="Invite a teammate" />
<bs:bsui-combobox-option value="rotate-key" label="Rotate API key" />
<bs:bsui-combobox-option value="theme" label="Toggle dark mode" />
<bs:bsui-combobox-option value="docs" label="Open documentation" />
<bs:bsui-combobox-option value="support" label="Contact support" />
</bs:bsui-combobox-popup>
</bs:bsui-combobox>
</bs:bsui-dialog-content>
</bs:bsui-dialog-popup>
</bs:bsui-dialog>
<bs:bsui-text content="or press" variant="caption" tag="span" />
<bs:bsui-kbd label="Cmd" />
<bs:bsui-kbd label="K" />
</bs:bsui-stack>工作原理
打开对话框时,焦点会直接移至组合框输入框;其 store 会在上下文中根据每次按键筛选目标列表。按 Enter 会执行高亮的命令并关闭两层界面;按 Escape 则先关闭列表,再关闭对话框。
此页面上的每项行为都是 WordPress Interactivity API:每个组件都会注册自己的 store,在服务器渲染的上下文中初始化状态,并通过上方标记中的指令绑定事件。没有针对单个页面的 JavaScript。