guide

Openers & Triggers

data-toggle, data-open, and data-close wire any element to a component without JavaScript.

Put data-toggle="#id" on any element to toggle the component with that id, or data-open="#id" to only open it. data-close closes the nearest enclosing dialog, or the one matched by its selector. The element that opened a dialog receives focus back when it closes.

<button type="button" class="z-button z-button-primary" data-toggle="#cmd-triggers">Toggle</button>
<button type="button" class="z-button z-button-secondary" data-open="#cmd-triggers">Open</button>

<z-cmd id="cmd-triggers">
  <select data-fn="data-source" hidden>
    <optgroup label="Actions">
      <option value="ok">OK</option>
    </optgroup>
  </select>
</z-cmd>

The same actions are available as methods:

triggers/snippet-api.js
const palette = document.querySelector('#cmd-triggers');

await palette.show(); // open, remembering the current focus for restore
await palette.hide(); // close and restore focus
await palette.toggle(); // flip the open state