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…
Platform-aware keyboard shortcut display and declarative action binding. On <kbd> elements renders platform symbols; on other elements binds keyboard shortcuts to actions, honouring the user's single-key shortcut preference (WCAG 2.1.4).
Overview
data-hotkey has two jobs, depending on the element it is on:
Display — on a <kbd>, it renders the combo for the user's platform: ⌘K on Mac, Ctrl+K elsewhere, with a spelled-out name for screen readers.
Action — on any other element (a button, input, <details>, form), it binds a real keyboard shortcut that clicks, focuses, submits or toggles that element. It upgrades the native accesskeyattribute.
Display and action
12345
<!-- Display only --><kbddata-hotkey="meta+k">Ctrl+K</kbd><!-- Action: the shortcut clicks the button --><buttontype="button"data-hotkey="meta+s">Save <kbddata-hotkey="meta+s">Ctrl+S</kbd></button>
Usage
Combo syntax
Keys are joined with +, modifiers first: meta+k, ctrl+shift+p, alt+f4, ?. Matching is case-insensitive.
Modifiers:meta (alias cmd) means Cmd on Mac and Ctrl elsewhere. The others are ctrl (control), alt (option) and shift.
Key aliases:esc, return, del, ins, up / down / left / right, space, pgup / pgdn, and plus (or a trailing +, as in ctrl++).
Shifted punctuation: for keys like ?, ! and +, Shift is not compared, because whether Shift is needed depends on the keyboard layout. ? and shift+? both fire on Shift+/ on a US keyboard, and ctrl++ fires whether or not Shift was needed.
Alt / Option combos: letters and digits also match by physical key (event.code). alt+k works on a Mac, where Option+K types "˚", and shift+1 works although the key types "!".
Display (<kbd>)
Reads the combo and detects the platform.
Renders an aria-hidden cap (<kbd>) for each key, plus a visually hidden spelled-out name ("Command Shift P").
The original text ("Ctrl+K") is the no-JS fallback. Running it again is a no-op. A changed combo rebuilds the caps.
Action binding (other elements)
All shortcuts share one keydown listener on the document. Each binding runs the element's action (data-hotkey-action).
Bound elements get aria-keyshortcuts (for example Control+S, Meta+K on Mac, Shift+?, Space), unless you set one yourself.
A binding is dropped when its element leaves the document, and rebound when any data-hotkey*attribute changes. It is skipped while the element is hidden, inert, disabled, or inside a hidden or inert ancestor. The toggle action still works on a hidden element itself, so it can show it again.
Ignored keystrokes: auto-repeat (holding a key fires once), IME composition, keystrokes another handler already handled (defaultPrevented), and, unless the binding has data-hotkey-global, keys typed into form fields or contenteditable.
When a binding fires, the browser's default action for that key is prevented.
Every bound element is listed in the <short-cuts> dialog.
Action bindings
12345678
<inputtype="search"id="search"data-hotkey="/"data-hotkey-action="focus"data-hotkey-label="Focus search"><buttontype="button"data-hotkey="meta+s"data-hotkey-global>Save <kbddata-hotkey="meta+s">Ctrl+S</kbd></button><detailsdata-hotkey="meta+i"data-hotkey-action="toggle"data-hotkey-label="Toggle info panel"><summary>Info panel</summary><p>Panel content.</p></details>
Overrides the label and spoken name of one key, e.g. data-label-ctrl="Strg". Read from the element or any ancestor. On Mac the modifier glyphs stay and only the spoken name changes.
data-hotkey-action
action
click (default) calls .click(). focus moves focus to the element. submit calls requestSubmit() on the closest form. toggle flips open on <details> / <dialog>, else the element's hidden.
data-hotkey-label
action
Description in the shortcuts dialog. Defaults to the element's accessible name: aria-label, aria-labelledby, its <label>, a <details>'s <summary>, or its text with <kbd> hints and hidden text left out. Then placeholder, title, or the combo.
data-hotkey-group
action
Group heading in the shortcuts dialog. Default "Page Actions".
data-hotkey-global
action
Fires even while the user is typing in a form field. This takes the key away from typing, so keep it to modifier combos such as Ctrl+S.
data-hotkey-scope
action
The shortcut fires only while focus is inside a region. The value is a CSS selector: the nearest matching ancestor, else the first match in the document. An empty value means the element itself. Scoped single-key shortcuts stay on when the user turns single-key shortcuts off (WCAG 2.1.4 "active only on focus").
Modifier Key Mapping
Modifier keys are automatically translated based on the user's platform:
Key name
Mac
Windows/Linux
meta, cmd
⌘ (spoken "Command")
Ctrl (spoken "Control")
alt, option
⌥ (spoken "Option")
Alt
shift
⇧ (spoken "Shift")
Shift
ctrl, control
⌃ (spoken "Control")
Ctrl (spoken "Control")
Named keys
Named keys get short labels on every platform:
Key name
Shown
Spoken
escape, esc
Esc
Escape
enter, return
Enter
Enter
tab, space, backspace, home, end
Tab, Space, Backspace, Home, End
as shown
delete, del / insert
Del / Ins
Delete / Insert
pageup / pagedown
PgUp / PgDn
Page up / Page down
arrowup (up), arrowdown, arrowleft, arrowright
↑ ↓ ← →
Up arrow, Down arrow, …
plus (or trailing +)
+
Plus
Any other key is displayed in uppercase (e.g., k becomes K).
Localised key names
Key names default to English. Override any of them with data-label-key on the element or an ancestor:
data-hotkey fires no events of its own. The action fires the element's own events (click, focus, submit, toggle). Adding or removing a binding dispatches vb:command-registry-change (detail: { action: 'add' | 'remove', element }) on the document, so <short-cuts> and <command-palette> can refresh.
Styling
The display hooks are kbd[data-hotkey] (an inline-flex row of caps that stays left-to-right in RTL pages) and its child kbd caps. Action-bound elements keep their own styles. Select them with [data-hotkey]:not(kbd) or [aria-keyshortcuts] if you want a visual hint.
Accessibility
Single-key shortcuts (WCAG 2.1.4)
A shortcut that is a single letter, digit, punctuation or symbol key (/, ?, j, with or without Shift) fires by accident for speech-input users and some keyboard users. WCAG 2.1.4 requires that users can turn such shortcuts off or remap them, or that they work only while the relevant region has focus. VB covers this site-wide:
The Single-Key Shortcuts switch in <settings-panel> (Accessibility) turns them all off. The choice is stored as charShortcuts in vb:settings:extensions and restored as soon as the hotkey code loads.
While it is off, <html data-char-shortcuts="off"> is set. You can also author that attribute to opt a page out.
While it is off, unscoped single-key shortcuts don't fire: data-hotkey actions, <short-cuts>'s ?, and any component built on VB's hotkey binder. They are also left out of the shortcuts dialog. Shortcuts with Ctrl, Cmd or Alt keep working, and so do named keys such as Escape.
Shortcuts with data-hotkey-scope stay active, because they only fire while focus is inside their region.
Prefer modifier combos for page-wide actions. If you use a single key, give the action a visible control as well.
Action-bound elements expose their shortcut through aria-keyshortcuts, which screen readers can announce.
Screen readers in browse mode use letter keys to navigate (H for headings, B for buttons), so the page never receives those keystrokes. Single-key shortcuts mostly work in focus mode, which is one more reason to prefer modifier combos.
data-hotkey-global overrides typing in form fields. Use it only for modifier combos users expect to work everywhere, such as Ctrl+S.
Don't rebind keys that browsers or assistive technology rely on (Ctrl+L, Ctrl+T, Ctrl+F, the arrow keys, Tab). VB does not detect clashes with browser shortcuts. In development it only logs a console warning when the same normalised combo is bound twice (meta+k and cmd+k, or ? and shift+?), and the last binding wins.
In the display form, the visible caps are aria-hidden and a visually hidden span carries the spelled-out combo ("Command Shift P"). Screen readers read the Mac glyphs inconsistently, and aria-label is not allowed on <kbd>.
Nested <kbd> inside <kbd> is valid HTML for key combinations. The caps keep left-to-right order in right-to-left pages.
Examples
Inline text, reference tables and tooltips
These are display-only. A reference table that lists browser or editor shortcuts such as Ctrl+Z documents them. Never put those combos on action elements, because binding them would replace the browser's own Undo or Select All.
Display patterns
1234567891011121314
<p>Press <kbddata-hotkey="meta+k">Ctrl+K</kbd> to open the search palette.</p><table><thead><tr><thscope="col">Action</th><thscope="col">Shortcut</th></tr></thead><tbody><tr><td>Search</td><td><kbddata-hotkey="meta+k">Ctrl+K</kbd></td></tr><tr><td>Undo</td><td><kbddata-hotkey="meta+z">Ctrl+Z</kbd></td></tr></tbody></table><tool-tip><buttontype="button">Search</button><templatedata-tooltip>Search <kbddata-hotkey="meta+k">Ctrl+K</kbd></template></tool-tip>
Dynamic elements
Elements added after page load are enhanced automatically, both <kbd> displays and action bindings. Removing an element removes its binding.