Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

commandfor

Declarative invoker buttons: commandfor names a target and command says what to do to it, opening dialogs and popovers or firing your own commands without click handlers.

Overview

Invoker commands let a button act on another element with no script. commandfor holds the id of the target, and command names the action: open a modal dialog, close it, toggle a popover, or send a custom command that your own code handles. They replace the onclick="dialog.showModal()" pattern and cover everything popovertarget does.

Applies to: <button> only. Both attributes are needed; the target can be any element with an id in the same document or shadow root.

Values

commandfor takes one id. command takes one of these keywords:

commandTargetEffect
show-modal<dialog>Opens it as a modal, like showModal(): top layer, backdrop, rest of the page inert.
close<dialog>Closes it, like close(). The button's value becomes the dialog's returnValue.
request-close<dialog>Asks it to close, like requestClose(): a cancel event fires first and script can prevent the close.
toggle-popover[popover]Opens or closes it, like popovertarget.
show-popover[popover]Opens it if closed.
hide-popover[popover]Closes it if open.
--anythingany elementA custom command. The browser does nothing itself; it fires a command event on the target for your script. The name must start with two dashes.
missing or unknown—Nothing happens.

There is no command for a non-modal dialog (show()) or for <details>. A built-in command sent to the wrong kind of element (for example show-modal to a popover) does nothing.

The command event

Before any action runs, the target receives a command event (a CommandEvent). event.command is the keyword and event.source is the button. Calling preventDefault() stops a built-in action.

Examples

Popover commands

As with popovertarget, the button becomes the popover's implicit anchor, so position-area places the popover next to it. See popover for the styling a bare popover needs in VB.

Custom commands

The third part of the demo sends --add and --reset to an <output>. One listener on the target handles every button that points at it.

Reading the result of a dialog

In Vanilla Breeze

  • No polyfill. VB relies on the browser for invoker commands. In a browser without them the button does nothing (see Browser support).
  • Command palette discovery. src/utils/command-init.js loads when the page has a [commandfor] or [data-command] element. It registers each [commandfor] button so a <command-palette discover> lists it, using the button's text as the label. Choosing the item clicks the button, so the native command runs. Override the label with data-command, set the group with data-command-group (default "Page Actions") and an icon with data-command-icon. Hidden buttons are left out of the list.
  • Keyboard shortcuts. data-shortcut on a registered button binds the shortcut and shows it in the palette. data-hotkey binds a shortcut that clicks any button, including invoker buttons.
  • Dialog styles (src/native-elements/dialog/styles.css): dialog[open] becomes a flex column with a fixed header and footer and a scrolling body, opens and closes with a fade and scale, and gets a blurred ::backdrop (--color-backdrop, --backdrop-blur). data-size and data-position give size variants and drawers; see <dialog>.
  • Popover styles: VB styles only [role="tooltip"][popover] and [popover="hint"]; see popover.

Accessibility

  • An invoker is a real <button>, so it is focusable and works with Enter and Space. Label it with the action ("Delete project"), not the mechanism ("Open dialog").
  • show-modal gives the full modal behaviour: focus moves into the dialog, the rest of the page becomes inert, and focus returns to the button when the dialog closes.
  • Give every dialog a name with aria-labelledby pointing at its heading.
  • Custom commands have no built-in feedback. If the result isn't visible where focus is, announce it; an <output> is a polite live region.

Browser support

  • commandfor, command and the command event: Baseline 2025 (Chrome 135, Firefox 144, Safari 26.2).
  • command="request-close": Chrome 139, Firefox 144, Safari 26.2.
  • closedby on <dialog>: Chrome 134, Firefox 141; not yet in a released Safari (as of November 2026).

For older browsers, popovertarget (Baseline 2024) covers popovers. For dialogs, open them from a click handler that calls showModal().

Gotchas

  • Buttons only. commandfor does nothing on <a>, <input> or other elements.
  • Custom names need --. command="add" is an unknown keyword and does nothing; command="--add" fires the event.
  • Inside a form, add type="button" so the button can never submit the form.
  • Listen on the target, not the button. The command event is dispatched to the element named by commandfor.
  • Use one mechanism per button. Don't put popovertarget and commandfor on the same button.

Related

Which to choose

  • commandfor + command — dialogs, popovers and custom actions on one element, all with the same pattern.
  • popovertarget — popovers only, with longer browser support.
  • data-toggle — flip an attribute that no command covers, such as hidden, open on <details>, or data-state.
  • A click handler — non-modal dialogs (show()) and browsers without invoker commands.
↑