命令
用途
Add your command HTML
Use <dialog class="command-dialog"> for the command palette variant.
HTML 结构
命令菜单可以独立使用,也可以在原生对话框中使用。结构是:
<dialog class="command-dialog">OptionalDialog variant. Wraps one direct child
<div class="command">. Addaria-labeloraria-labelledbyfor an accessible name.<div class="command">Root command menu. Can also be used standalone without the dialog wrapper. Add
data-filter="manual"when your app owns filtering, such as remote search or a local Lunr index.<header>Search input wrapper. The macro includes a search icon and input.
<input type="text" role="combobox">- Filter input. Use
aria-expanded="true"andaria-controls="{ MENU_ID }"to point to the command list.
<div role="menu" id="{ MENU_ID }">Command list. Set
data-emptyto customize the empty state.<div role="group" aria-labelledby="{ HEADING_ID }">Optional- Groups related command items. Hidden automatically when every item in the group is filtered out.
<span role="heading" id="{ HEADING_ID }">Optional- Group heading. Use an
idwhen the parent group usesaria-labelledby. <div role="menuitem">or<a role="menuitem">- Selectable command item. Use
<a>for navigation and<div>for actions. Supportsdata-filter,data-keywords,data-force,data-keep-command-open,aria-disabled="true", anddata-disabled="true". <span data-shortcut>Optional- Shortcut hint aligned to the inline end of the item.
<span data-indicator>Optional- Item indicator. It becomes visible with
data-checked="true"oraria-selected="true". <hr role="separator">Optional- Separator between groups/items. Hidden while filtering.
JavaScript API
示例
基本
对话框中的简单命令菜单。
快捷键
组
可滚动
RTL
将 dir="rtl" 添加到命令根或祖先。