Command Overview

The command component provides an accessible dropdown menu for presenting users with a list of actionable commands or selectable options. It combines the functionality of a popup with structured menu items and groups, making it ideal for command palettes, context menus, and option selectors.

When to Use

Use command components when:

  • Creating command palettes or quick action menus
  • Presenting contextual actions for specific items
  • Building dropdown menus with grouped options
  • Implementing selectable option lists with categories

Don't use command components for:

  • Simple navigation menus (use navigation components)
  • Form input selection (use select or combobox)
  • Primary page actions (use buttons directly)
  • Toggle switches or binary choices
Examples Basic Command Menu

A simple command dropdown with multiple action items. The component provides built-in keyboard navigation and accessibility features.

<dap-ds-command>
<dap-ds-button slot="trigger">Actions</dap-ds-button>
<dap-ds-command-item value="copy">Copy</dap-ds-command-item>
<dap-ds-command-item value="paste">Paste</dap-ds-command-item>
<dap-ds-command-item value="delete" disabled>Delete</dap-ds-command-item>
</dap-ds-command>
Grouped Commands

Organize related commands into logical groups for better user experience and visual hierarchy.

<dap-ds-command>
<dap-ds-button slot="trigger">File Operations</dap-ds-button>
<dap-ds-command-group label="Edit">
  <dap-ds-command-item value="cut">Cut</dap-ds-command-item>
  <dap-ds-command-item value="copy">Copy</dap-ds-command-item>
  <dap-ds-command-item value="paste">Paste</dap-ds-command-item>
</dap-ds-command-group>
<dap-ds-command-group label="File">
  <dap-ds-command-item value="save">Save</dap-ds-command-item>
  <dap-ds-command-item value="export">Export</dap-ds-command-item>
  <dap-ds-command-item value="print">Print</dap-ds-command-item>
</dap-ds-command-group>
</dap-ds-command>
Selectable Options

Command items can be made selectable to show the current selection state with visual indicators.

<dap-ds-command>
<dap-ds-button slot="trigger">View Options</dap-ds-button>
<dap-ds-command-group label="Display">
  <dap-ds-command-item value="grid" selectable>Grid View</dap-ds-command-item>
  <dap-ds-command-item value="list" selectable>List View</dap-ds-command-item>
  <dap-ds-command-item value="card" selectable>Card View</dap-ds-command-item>
</dap-ds-command-group>
</dap-ds-command>
Exclusive Selection Groups

Use exclusive groups when only one option should be selected at a time, similar to radio button behavior.

<dap-ds-command>
<dap-ds-button slot="trigger">Sort By</dap-ds-button>
<dap-ds-command-group label="Sort Options" exclusive>
  <dap-ds-command-item value="name" selectable>Name</dap-ds-command-item>
  <dap-ds-command-item value="date" selectable>Date Modified</dap-ds-command-item>
  <dap-ds-command-item value="size" selectable>File Size</dap-ds-command-item>
</dap-ds-command-group>
</dap-ds-command>
Full-Width Commands

For mobile interfaces or special contexts, commands can take the full width of the screen.

<dap-ds-command fullWidth>
<dap-ds-button slot="trigger">Mobile Menu</dap-ds-button>
<dap-ds-command-group label="Navigation">
  <dap-ds-command-item value="home">Home</dap-ds-command-item>
  <dap-ds-command-item value="profile">Profile</dap-ds-command-item>
  <dap-ds-command-item value="settings">Settings</dap-ds-command-item>
</dap-ds-command-group>
<dap-ds-command-group label="Actions">
  <dap-ds-command-item value="help">Help</dap-ds-command-item>
  <dap-ds-command-item value="logout">Sign Out</dap-ds-command-item>
</dap-ds-command-group>
</dap-ds-command>
Custom Triggers

Commands can use any element as a trigger, not just buttons.

<dap-ds-command>
<div slot="trigger" style={{
  padding: 'var(--dds-spacing-400)',
  border: 'var(--dds-border-width-base) solid var(--dds-border-neutral-subtle)',
  borderRadius: 'var(--dds-radius-base)',
  cursor: 'pointer',
  background: 'var(--dds-background-neutral-base)'
}}>
  Click for options
</div>
<dap-ds-command-item value="option1">Option 1</dap-ds-command-item>
<dap-ds-command-item value="option2">Option 2</dap-ds-command-item>
<dap-ds-command-item value="option3">Option 3</dap-ds-command-item>
</dap-ds-command>
Real-World Patterns Context Menu

Implement context menus for table rows or content items.

<div style={{
border: 'var(--dds-border-width-base) solid var(--dds-border-neutral-subtle)',
borderRadius: 'var(--dds-radius-base)',
padding: 'var(--dds-spacing-600)'
}}>
<dap-ds-stack direction="row" justify="between" align="center">
  <div>
    <dap-ds-typography variant="h5">Document.pdf</dap-ds-typography>
    <dap-ds-typography variant="description">
      Modified 2 hours ago
    </dap-ds-typography>
  </div>
  <dap-ds-command>
    <dap-ds-button slot="trigger" variant="subtle" shape="circle" aria-label="More options">
      <dap-ds-icon name="more-line"></dap-ds-icon>
    </dap-ds-button>
    <dap-ds-command-item value="download">
      <dap-ds-stack direction="row">
        <dap-ds-icon name="download-line"></dap-ds-icon>
        <span>Download</span>
      </dap-ds-stack>
    </dap-ds-command-item>
    <dap-ds-command-item value="share">
      <dap-ds-stack direction="row">
        <dap-ds-icon name="share-line"></dap-ds-icon>
        <span>Share</span>
      </dap-ds-stack>
    </dap-ds-command-item>
    <dap-ds-command-item value="rename">
      <dap-ds-stack direction="row">
        <dap-ds-icon name="edit-line"></dap-ds-icon>
        <span>Rename</span>
      </dap-ds-stack>
    </dap-ds-command-item>
    <dap-ds-command-item value="delete">
      <dap-ds-stack direction="row">
        <dap-ds-icon name="delete-bin-line"></dap-ds-icon>
        <span>Delete</span>
      </dap-ds-stack>
    </dap-ds-command-item>
  </dap-ds-command>
</dap-ds-stack>
</div>
Bulk Actions

Provide bulk operations for selected items in lists or tables.

<div style={{
border: 'var(--dds-border-width-base) solid var(--dds-border-neutral-subtle)',
borderRadius: 'var(--dds-radius-base)',
padding: 'var(--dds-spacing-600)'
}}>
<dap-ds-stack direction="row" justify="between" align="center">
  <dap-ds-typography variant="body">3 items selected</dap-ds-typography>
  <dap-ds-command>
    <dap-ds-button slot="trigger" variant="outline">
      Bulk Actions
    </dap-ds-button>
    <dap-ds-command-group label="Actions">
      <dap-ds-command-item value="download-all">Download All</dap-ds-command-item>
      <dap-ds-command-item value="move">Move to Folder</dap-ds-command-item>
      <dap-ds-command-item value="archive">Archive</dap-ds-command-item>
    </dap-ds-command-group>
    <dap-ds-command-group label="Dangerous">
      <dap-ds-command-item value="delete-all">Delete All</dap-ds-command-item>
    </dap-ds-command-group>
  </dap-ds-command>
</dap-ds-stack>
</div>
Accessibility Built-in Features
  • Full keyboard navigation with Arrow keys, Home, End, Enter, and Escape
  • Screen reader support with proper ARIA roles and live announcements
  • Focus management with roving tabindex pattern
  • Selection announcements with position and total count
Keyboard Navigation
  • Arrow Down/Up: Navigate through command items
  • Home/End: Jump to first/last item
  • Enter/Space: Activate the focused command item
  • Escape: Close the command menu
  • Tab: Move focus to/from the trigger element
ARIA Support

The component automatically provides:

  • role="menu" for the command container
  • role="menuitem" for each command item
  • aria-selected states for selectable items
  • aria-expanded on the trigger element
  • Live region announcements for navigation
Best Practices
<dap-ds-stack direction="column">
<dap-ds-typography variant="h4">Accessible command examples:</dap-ds-typography>
<dap-ds-stack direction="row">
  <dap-ds-command aria-label="Document actions">
    <dap-ds-button slot="trigger" aria-label="Document options">
      <dap-ds-icon name="more-line"></dap-ds-icon>
    </dap-ds-button>
    <dap-ds-command-item value="edit">Edit Document</dap-ds-command-item>
    <dap-ds-command-item value="share">Share with Others</dap-ds-command-item>
    <dap-ds-command-item value="delete">Delete Permanently</dap-ds-command-item>
  </dap-ds-command>
  
  <dap-ds-command aria-labelledby="sort-label">
    <dap-ds-button slot="trigger" id="sort-label">
      Sort Options
    </dap-ds-button>
    <dap-ds-command-group label="Sort by" exclusive>
      <dap-ds-command-item value="name" selectable>Name (A-Z)</dap-ds-command-item>
      <dap-ds-command-item value="date" selectable>Date Modified</dap-ds-command-item>
    </dap-ds-command-group>
  </dap-ds-command>
</dap-ds-stack>
</dap-ds-stack>
Technical Details

The command component is built on top of the popup component, inheriting all its positioning and interaction capabilities while adding specialized menu behavior and accessibility features.

Importing
import { DapDSCommand } from 'dap-design-system'
Importing React
import { DapDSCommandReact } from 'dap-design-system/react'
Tree-Shakeable Imports

For optimal bundle sizes, use the tree-shakeable import syntax:

import { DapDSCommand } from 'dap-design-system/components'
Attributes
PropertyTypeDefaultDescription
valuestring, nullnullThe value of the command.
fullWidthbooleanfalseWhether the command popup should take full width of the screen.
ariaLabelledBystring, undefinedID of element that labels the command dropdown.
placement'top', 'right' , 'bottom' , 'left' , 'top-start' , 'top-end' , 'bottom-start' , 'bottom-end' , 'left-start' , 'left-end' , 'right-start' , 'right-end''bottom-start'The placement of the popup.
overflowbooleantrueWhether the popup should overflow.
size'xs', 'sm' , 'lg'The size of the popup.
disabledbooleanThe disabled state of the popup.
openedbooleanThe open state of the popup.
floatingStrategy'absolute', 'fixed'The floating strategy of the popup.
offsetnumberThe offset of the popup.
syncbooleanWhether the popup should sync its width with the trigger.
maxHeightnumber, 'auto'The maximum height of the popup.
maxWidthnumber, 'auto'The maximum width of the popup.
hasArrowbooleanWhether the popup has an arrow.
Slots
NameDescription
triggerThe trigger element for the command dropdown.
(default)The command items.
Events
Event NameDescriptionType
dds-changeFired when the command value changes.{value: string }
dds-openedFired when the popup is opened.{void }
dds-closedFired when the popup is closed.{void }
dds-closeFired when the popup should be closed.{void }
CSS Parts
Part NameDescription
popupThe main popup container.
arrowThe arrow of the popup.
How to Use CSS Parts

You can style CSS parts using the ::part() pseudo-element selector:

/* Target a specific part */
.my-custom-dap-ds-command::part(popup) {
  /* Your custom styles */
}

/* Target multiple parts */
.my-custom-dap-ds-command::part(popup),
.my-custom-dap-ds-command::part(arrow) {
  /* Shared styles */
}

Example usage:

<dap-ds-command class="my-custom-dap-ds-command">
  Command
</dap-ds-command>
.my-custom-dap-ds-command::part(popup) {
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

CSS parts allow you to style internal elements of the component while maintaining encapsulation. Learn more in our styling guide.

CSS Custom Properties
Property NameDescription
--dds-popup-z-indexZ-index of the popup (default: var(--dds-z-index-20))
--dds-popup-paddingDefault padding of the popup (default: var(--dds-spacing-400))
--dds-popup-padding-xsPadding of the popup when size is xs (default: var(--dds-spacing-200))
--dds-popup-padding-lgPadding of the popup when size is lg (default: var(--dds-spacing-500))
--dds-popup-border-widthBorder width of the popup (default: var(--dds-border-width-base))
--dds-popup-border-radiusBorder radius of the popup (default: var(--dds-radius-base))
--dds-popup-border-colorBorder color of the popup (default: var(--dds-border-neutral-subtle))
--dds-popup-backgroundBackground color of the popup (default: var(--dds-background-neutral-base))
--dds-popup-colorText color of the popup (default: var(--dds-text-neutral-base))
--dds-popup-arrow-sizeSize of the popup arrow (default: var(--dds-tooltip-arrow-size))
How to Use CSS Custom Properties

CSS custom properties (CSS variables) can be set directly on the component or in your stylesheet:

Method 1: Inline styles (Quick customization)

<dap-ds-command
  style="--dds-popup-z-index: value; --dds-popup-padding: value;">
  Command
</dap-ds-command>

Method 2: CSS classes (Reusable styles)

.my-custom-dap-ds-command {
  --dds-popup-z-index: value;
  --dds-popup-padding: value;
  --dds-popup-padding-xs: value;
}
<dap-ds-command class="my-custom-dap-ds-command">
  Command
</dap-ds-command>

Method 3: Global theme customization

/* Apply to all instances */
dap-ds-command {
  --dds-popup-z-index: value;
  --dds-popup-padding: value;
}

CSS custom properties inherit through the Shadow DOM, making them perfect for theming. Changes apply immediately without rebuilding.

Components Command group <dap-ds-command-group/> Attributes
PropertyTypeDefaultDescription
labelstring, undefinedThe label of the command group.
exclusivebooleanfalseWhether the command group is exclusive, only one item can be selected at a time.
Slots
NameDescription
(default)The default slot for the command group.
Events

No custom events available.

CSS Parts
Part NameDescription
baseThe base part of the command group.
labelThe label part of the command group.
itemsThe items part of the command group.
CSS Custom Properties
Property NameDescription
--dds-command-group-gapThe gap between command group elements. (default: var(--dds-spacing-100))
--dds-command-group-margin-bottomThe bottom margin of the command group. (default: var(--dds-spacing-200))
--dds-command-group-border-radiusThe border radius of the command group. (default: var(--dds-radius-small))
--dds-command-group-label-font-weightThe font weight of the command group label. (default: var(--dds-font-weight-bold))
--dds-command-group-items-gapThe gap between command items. (default: var(--dds-spacing-100))
Command item <dap-ds-command-item/> Attributes
PropertyTypeDefaultDescription
valuestring, undefinedThe value of the command item.
disabledbooleanfalseWhether the command item is disabled.
namestringThe name of the button
hrefstringThe Href of the button. If this present the button will be rendered as an anchor <a></a> element.
target'_blank', '_self' , '_parent' , '_top''_self'The target of the button
relstring'noreferrer noopener'The rel of the button link. Default is noreferrer noopener.
selectablebooleanfalseWhether the command item is selectable.
selectedbooleanfalseWhether the command item is selected.
closeOnSelectstring'true'Whether the command item should close the command when selected.
Slots
NameDescription
(default)The label of the command item.
checkThe check of the command item.
Events
Event NameDescriptionType
dds-command-item-clickFired when the command item is clicked.{value: string, closeOnSelect: boolean }
CSS Parts
Part NameDescription
baseThe base part of the command item.
contentThe content part of the command item.
labelThe label part of the command item.
CSS Custom Properties
Property NameDescription
--dds-command-item-paddingThe padding of the command item (default: var(--dds-spacing-100) var(--dds-spacing-200))
--dds-command-item-backgroundThe background color of the command item (default: none)
--dds-command-item-colorThe text color of the command item (default: var(--dds-text-primary-base))
--dds-command-item-hover-backgroundThe background color of the command item on hover (default: var(--dds-transparent-black-subtle))
--dds-command-item-selected-backgroundThe background color of the selected command item (default: var(--dds-transparent-black-subtle))