Commands
<div id="demo-command-standalone" class="command border" aria-label="Command menu">
<header><i class="icon icon-search" aria-hidden="true"></i>
<input type="text" id="demo-command-standalone-input" placeholder="Type a command or search..." autocomplete="off" autocorrect="off" spellcheck="false" aria-autocomplete="list" role="combobox" aria-expanded="true" aria-controls="demo-command-standalone-menu" />
</header>
<div role="menu" id="demo-command-standalone-menu" aria-orientation="vertical" data-empty="No results found.">
<div role="group" aria-labelledby="suggestions">
<span role="heading" id="suggestions">Suggestions</span>
<div role="menuitem" data-label="Calendar" data-keywords="date event schedule"><i class="icon icon-calendar" aria-hidden="true"></i>
<span>Calendar</span>
</div>
<div role="menuitem" data-label="Search Emoji" data-keywords="emoji smile reaction"><i class="icon icon-smile" aria-hidden="true"></i>
<span>Search Emoji</span>
</div>
<div role="menuitem" aria-disabled="true"><i class="icon icon-calculator" aria-hidden="true"></i>
<span>Calculator</span>
</div>
</div>
<hr role="separator" />
<div role="group" aria-labelledby="settings">
<span role="heading" id="settings">Settings</span>
<div role="menuitem" data-label="Profile" data-keywords="user account"><i class="icon icon-user" aria-hidden="true"></i>
<span>Profile</span>
<span data-shortcut>⌘P</span>
</div>
<div role="menuitem" data-label="Billing" data-keywords="invoice payment"><i class="icon icon-credit-card" aria-hidden="true"></i>
<span>Billing</span>
<span data-shortcut>⌘B</span>
</div>
<div role="menuitem" data-label="Settings" data-keywords="config preferences"><i class="icon icon-settings" aria-hidden="true"></i>
<span>Settings</span>
<span data-shortcut>⌘S</span>
</div>
</div>
</div>
</div>
In a dialog, as a command palette
<button type="button" class="btn" data-variant="outline" data-dialog-open="command-palette">Open</button>
<dialog id="command-palette" class="command-dialog" aria-label="Command menu">
<div class="command">
<header><i class="icon icon-search" aria-hidden="true"></i>
<input type="text" id="command-palette-input" placeholder="Type a command or search..." autocomplete="off" autocorrect="off" spellcheck="false" aria-autocomplete="list" role="combobox" aria-expanded="true" aria-controls="command-palette-menu" />
</header>
<div role="menu" id="command-palette-menu" aria-orientation="vertical" data-empty="No results found.">
<div role="group" aria-labelledby="command-palette-suggestions">
<span role="heading" id="command-palette-suggestions">Suggestions</span>
<div role="menuitem" data-label="Calendar" data-keywords="date event schedule"><i class="icon icon-calendar" aria-hidden="true"></i>
<span>Calendar</span>
</div>
<div role="menuitem" data-label="Search Emoji" data-keywords="emoji smile reaction"><i class="icon icon-smile" aria-hidden="true"></i>
<span>Search Emoji</span>
</div>
<div role="menuitem" aria-disabled="true"><i class="icon icon-calculator" aria-hidden="true"></i>
<span>Calculator</span>
</div>
</div>
<hr role="separator" />
<div role="group" aria-labelledby="command-palette-settings">
<span role="heading" id="command-palette-settings">Settings</span>
<div role="menuitem" data-label="Profile" data-keywords="user account"><i class="icon icon-user" aria-hidden="true"></i>
<span>Profile</span>
<span data-shortcut>⌘P</span>
</div>
<div role="menuitem" data-label="Billing" data-keywords="invoice payment"><i class="icon icon-credit-card" aria-hidden="true"></i>
<span>Billing</span>
<span data-shortcut>⌘B</span>
</div>
<div role="menuitem" data-label="Settings" data-keywords="config preferences"><i class="icon icon-settings" aria-hidden="true"></i>
<span>Settings</span>
<span data-shortcut>⌘S</span>
</div>
</div>
</div>
</div>
</dialog>
Searching records, with filters
<div id="demo-command-records" class="command border" aria-label="Search">
<header><i class="icon icon-search" aria-hidden="true"></i>
<span class="badge" data-variant="secondary" data-filter-badge hidden><span data-name></span><button type="button" aria-label="Remove filter"><i class="icon icon-x" aria-hidden="true"></i></button></span>
<input type="text" id="demo-command-records-input" placeholder="Search orders and customers, or type / for filters..." autocomplete="off" autocorrect="off" spellcheck="false" aria-autocomplete="list" role="combobox" aria-expanded="true" aria-controls="demo-command-records-menu" />
</header>
<div data-filters aria-label="Filters">
<button type="button" class="btn" data-variant="outline" data-size="xs" data-filter="orders" data-suggested><i class="icon icon-shopping-bag" aria-hidden="true"></i>
<span data-name>Orders</span>
<span data-count></span>
</button>
<button type="button" class="btn" data-variant="outline" data-size="xs" data-filter="customers" data-suggested><i class="icon icon-user" aria-hidden="true"></i>
<span data-name>Customers</span>
<span data-count></span>
</button>
</div>
<div role="menu" id="demo-command-records-menu" aria-orientation="vertical" data-empty="No results found." data-limit="3">
<div role="group" data-results data-filter="orders" aria-labelledby="demo-command-records-orders">
<span role="heading" id="demo-command-records-orders">Orders</span>
<a role="menuitem" href="#" data-label="#1042" data-keywords="Maya Okafor"><i class="icon icon-shopping-bag" aria-hidden="true"></i>
<span>#1042</span>
<span data-description>Maya Okafor, $72.18</span>
<span class="badge" data-variant="warning">Open</span>
</a>
<a role="menuitem" href="#" data-label="#1041" data-keywords="Maya Okafor"><i class="icon icon-shopping-bag" aria-hidden="true"></i>
<span>#1041</span>
<span data-description>Maya Okafor, $344.97</span>
<span class="badge" data-variant="info">Paid</span>
</a>
<a role="menuitem" href="#" data-label="#1040" data-keywords="Liam Chen"><i class="icon icon-shopping-bag" aria-hidden="true"></i>
<span>#1040</span>
<span data-description>Liam Chen, $59.99</span>
<span class="badge" data-variant="info">Paid</span>
</a>
</div>
<div role="group" data-results data-filter="customers" aria-labelledby="demo-command-records-customers">
<span role="heading" id="demo-command-records-customers">Customers</span>
<a role="menuitem" href="#" data-label="Maya Okafor" data-keywords="maya.okafor@example.com"><i class="icon icon-user" aria-hidden="true"></i>
<span>Maya Okafor</span>
<span data-description>maya.okafor@example.com</span>
</a>
<a role="menuitem" href="#" data-label="Liam Chen" data-keywords="liam.chen@example.com"><i class="icon icon-user" aria-hidden="true"></i>
<span>Liam Chen</span>
<span data-description>liam.chen@example.com</span>
</a>
</div>
<div role="group" data-filter-list aria-labelledby="demo-command-records-filters">
<span role="heading" id="demo-command-records-filters">Filters</span>
<div role="menuitem" data-filter="orders" data-label="Orders"><i class="icon icon-shopping-bag" aria-hidden="true"></i>
<span>Orders</span>
</div>
<div role="menuitem" data-filter="customers" data-label="Customers"><i class="icon icon-user" aria-hidden="true"></i>
<span>Customers</span>
</div>
</div>
<div role="group" aria-labelledby="demo-command-records-pages">
<span role="heading" id="demo-command-records-pages">Pages</span>
<a role="menuitem" href="#" data-label="Orders"><i class="icon icon-shopping-bag" aria-hidden="true"></i>
<span>Orders</span>
</a>
<a role="menuitem" href="#" data-label="Customers"><i class="icon icon-user" aria-hidden="true"></i>
<span>Customers</span>
</a>
</div>
<div role="menuitem" data-more="20"><i class="icon icon-list-filter" aria-hidden="true"></i>
<span>Show <span data-count></span> more results</span>
</div>
</div>
</div>
API Reference
Attributes
| Attribute | On | Values | Default | Description |
|---|---|---|---|---|
| data-label | an item | text | the item's text | The name the search matches, for an item whose content is more than text. |
| data-keywords | an item | words | none | Extra words the search matches without showing them. |
| aria-disabled | an item | "true" | none | The item is skipped by the keyboard and cannot be chosen. |
| aria-hidden | an item | "true", "false" | set by the script | "true" on an item the search has filtered out. |
| data-results | a group | present or absent | absent | The group holds records. It shows while the field has text, or while its filter is chosen. |
| data-filter | a results group, a filter button, a filter item | a key, such as "orders" | none | Names the filter. Choosing it shows only the results groups with the same key. The command list carries the chosen key as its own data-filter. |
| data-filters | a div after the header | present | none | The row of filter buttons. Each button's [data-count] is filled with the number of records it would show. |
| data-suggested | a filter button | present or absent | absent | The button shows while the field is empty. Without it, a button shows only while it has a match. |
| data-filter-list | a group | present | none | The filters listed when the field starts with "/". Choosing one chooses its data-filter and empties the field. |
| data-filter-badge | a badge in the header | present | none | Names the chosen filter in its [data-name]. Its button removes the filter. |
| data-limit | the menu | a number | no limit | The most records shown at once. |
| data-more | an item | a number | none | Show more: choosing it shows that many more records. Its [data-count] says how many. |
| aria-busy | a results group | "true" | absent | The group's records are on their way and none show. The menu is then aria-busy too, set by the script, and says Searching... in place of No results found. |
| data-description | a span in an item | present | none | Muted text after the item's name, cut with an ellipsis when long. |
| data-hint | a span in an item | present | none | The item's keys, as kbd elements and what each does. It shows while the item is active. |
| data-tab-filter | an item | a filter's key | none | Tab on the active item chooses that filter and empties the field. |
Keyboard
| Key | Description |
|---|---|
| Arrow Down, Arrow Up | Move to the next or the previous item. A disabled or hidden item is skipped. |
| Enter | Chooses the active item, as a click on it does. |
| / | Typed first in the field: lists the filters. |
| Backspace | In an empty field: removes the chosen filter. |
| Tab | On an item with data-tab-filter: chooses that filter. |
| Escape | In a dialog.command-dialog: closes the dialog. This is the dialog's own behaviour. |
The command list has no methods and sends no events of its own. Each item is a link or a button; listen for its click.
Inside a dialog with the class command-dialog, choosing an item closes the dialog, except a filter item and Show more.
Once the script has started it, the element carries data-command-initialized="true" and sends tsugi:initialized. The methods and properties above are on the element itself.