--- layout: layouts/page.njk title: Command description: Fast, composable command menu for quick navigation and actions. toc: - label: Usage id: usage children: - label: HTML + JavaScript id: usage-html-js children: - label: "Step 1: Include the JavaScript files" id: usage-html-js-1 - label: "Step 2: Add your command HTML" id: usage-html-js-2 - label: HTML structure id: usage-html-js-3 - label: JavaScript events id: usage-html-js-4 - label: Jinja and Nunjucks id: usage-macro - label: Examples id: examples children: - label: Dialog id: example-dialog --- {% from "macros/code_preview.njk" import code_preview %} {% from "macros/code_block.njk" import code_block %} {% from "command.njk" import command, command_dialog %} {% macro command_items(suggestions_id="suggestions", settings_id="settings") %}
You can either include the JavaScript file for all the components, or just the one for this component by adding this to the <head> of your page:
You can use the command menu standalone:
Wrap the command menu in a <dialog class="command-dialog"> to display in a dialog:
<dialog class="command-dialog"> Optional<div class="command"> to display as a modal. Uses native <dialog> behavior and requires aria-label or aria-labelledby for accessibility.
<div class="command"><header><input type="text">role="combobox": indicates the input controls a menu with filteringaria-expanded="true": the menu is always expandedaria-controls="{ MENU_ID }": points to the menu's id<div role="menu">id="{ MENU_ID }" refered to by the input's aria-controls attribute.
<div role="menuitem"> or <a role="menuitem"><a> for navigation links, or <div> for actions. In a command-dialog, clicking a menuitem automatically closes the dialog unless the data-keep-command-open attribute is present. Optional attributes:
href: If present on an <a>, the item navigates to that URLdata-filter: custom text used for filtering (if different from displayed content, e.g., data-filter="calendar event")data-keywords: additional keywords for enhanced filtering (e.g., data-keywords="calendar event date")data-force: forces the item to always display, regardless of filter (e.g., data-force)aria-disabled="true": marks item as disabled (excluded from keyboard navigation and filtering)<hr role="separator"> Optional<div role="group"> Optionalaria-labelledby attribute to link to a heading.<span role="heading">id attribute if you use the aria-labelledby attribute on the group.basecoat:initializedbasecoat:initialized event on itself.You can use the command() or command_dialog() Nunjucks or Jinja macros for this component.
You can also use the items parameter to pass an array of items:
You can use some simple JavaScript to open the command menu with a keyboard shortcut (in this case ⌘J).