Composition

Keyboard and focus

A settings workspace you can operate entirely from the keyboard. Every interaction here is native: Tab moves between controls, arrow keys move within a radio group, Enter and Space open disclosures, and modal surfaces trap and restore focus. Use it to check focus visibility and order.

What to notice

Live composition

Density
Keyboard shortcuts
Ctrl + K
Open the command palette (application shortcut)
Esc
Close the open dialog or popover

Commands

Esc

Suggested

Keyboard help

HTML

HTML · Keyboard and focus Raw HTML for HTML · Keyboard and focus
<div class="forma-stack">
  <forma-segmented-control class="forma-component-tag">
    <fieldset class="forma-field">
      <legend class="forma-field__label">Density</legend>
      <div class="forma-segmented">
        <label class="forma-segment"><input type="radio" name="keyboard-density" value="comfortable" checked><span>Comfortable</span></label>
        <label class="forma-segment"><input type="radio" name="keyboard-density" value="compact"><span>Compact</span></label>
        <label class="forma-segment"><input type="radio" name="keyboard-density" value="dense"><span>Dense</span></label>
      </div>
    </fieldset>
  </forma-segmented-control>

  <forma-disclosure class="forma-component-tag">
    <details class="forma-disclosure">
      <summary>Keyboard shortcuts</summary>
      <div class="forma-disclosure__content">
        <dl class="forma-key-value-list">
          <div><dt><kbd>Ctrl</kbd> + <kbd>K</kbd></dt><dd>Open the command palette (application shortcut)</dd></div>
          <div><dt><kbd>Esc</kbd></dt><dd>Close the open dialog or popover</dd></div>
        </dl>
      </div>
    </details>
  </forma-disclosure>

  <forma-command-palette class="forma-component-tag">
    <button type="button" commandfor="keyboard-palette" command="show-modal">Open command palette</button>
    <dialog class="forma-command-palette" id="keyboard-palette" aria-labelledby="keyboard-palette-title">
      <header class="forma-command-palette__header">
        <h3 id="keyboard-palette-title">Commands</h3>
        <kbd>Esc</kbd>
      </header>
      <label class="forma-visually-hidden" for="keyboard-palette-search">Find a command</label>
      <input id="keyboard-palette-search" type="search" placeholder="Type a command">
      <div class="forma-command-palette__group">
        <h4>Suggested</h4>
        <button type="button"><span>Create project</span></button>
        <button type="button"><span>Invite teammate</span></button>
        <button type="button" disabled><span>Publish report</span><small>Unavailable until validation passes</small></button>
      </div>
    </dialog>
  </forma-command-palette>

  <forma-button class="forma-component-tag">
    <div class="forma-actions">
      <button type="submit">Save preferences</button>
      <a class="forma-button" href="#keyboard-help">Keyboard help</a>
    </div>
  </forma-button>
</div>

Click or tap the code once to select all of it, then copy.

Components used