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…
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.
Dialog commands
1234567891011121314
<buttontype="button"commandfor="delete-dialog"command="show-modal">Delete project</button><dialogid="delete-dialog"closedby="any"aria-labelledby="delete-title"><header><h3id="delete-title">Delete "Spring launch"?</h3></header><section><p>The project and its 12 tasks are removed for everyone.</p></section><footer><buttontype="button"class="secondary"commandfor="delete-dialog"command="request-close">Keep project</button><buttontype="button"commandfor="delete-dialog"command="close"value="delete">Delete</button></footer></dialog>
Values
commandfor takes one id. command takes one of these keywords:
command
Target
Effect
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.
--anything
any element
A 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
toggle-popover
12
<buttontype="button"commandfor="shortcuts"command="toggle-popover">Keyboard shortcuts</button><pid="shortcuts"popover><kbd>Ctrl</kbd> + <kbd>K</kbd> opens search. <kbd>?</kbd> shows this list.</p>
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.
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).