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…
Right-click context menu with keyboard navigation and viewport-aware positioning.
Description
The <context-menu> component provides a custom right-click menu that opens at the cursor position. It supports keyboard navigation, separators, danger items, and disabled states. Shares menu styling patterns with <drop-down>.
It is keyboard-operable too: a trigger that is not already focusable gets tabindex="0", and Shift+F10 or the ContextMenu key opens the menu while focus is on the trigger or on anything inside it. Focus returns to where it was when the menu closes. Any action in a context menu should still be reachable another way — a toolbar button or inline control — because touch users and many screen reader users never right-click.
Right-click target area. Made focusable (tabindex="0") when it is not already. A control (button, link, or a focusable element with a widget role) gets aria-haspopup="menu", aria-expanded and aria-controls; any other trigger gets an aria-description instead. These are removed on disconnect
<menu>
yes
Context menu with <li> items holding <button> or <a> actions; <li data-group> labels and <li role="separator"> rows
Group label row. It and the items after it (up to the next label or separator) are wrapped in role="group" named by the label
data-shortcut
button, a
string
Keyboard shortcut bound page-wide (hotkey-bind, preventDefault) and shown as a badge, e.g. 'f2' or 'shift+d'. Never use clipboard combos.
data-disabled
button, a
boolean
Disabled item: aria-disabled="true", stays in the arrow-key order, cannot be activated
data-value
button, a
string
Value reported in context-menu:select detail.value and the items property
Disabled Items
Mark an item data-disabled. It gets aria-disabled="true", stays in the arrow-key order (so screen reader users learn it exists, per the APG menu pattern), and cannot be activated: no click handlers run, the menu stays open, and its shortcut does nothing. A native disabled button is skipped by the arrow keys because it cannot take focus.
Add data-shortcut to any button to display a keyboard shortcut badge and bind a real global keyboard shortcut. Pressing the shortcut anywhere on the page (outside text fields) triggers the button's click. The badge is platform-aware — meta shows ⌘ on Mac and Ctrl elsewhere — and the item gets a matching aria-keyshortcuts. Shortcuts are cleaned up when the component disconnects.
Warning: the binding is page-wide and calls preventDefault(). Binding meta+c, meta+x, meta+v or meta+a would break native copy, cut, paste and select-all everywhere on the page. Choose combos that do not shadow browser or OS shortcuts (function keys and shift+ letters are safe choices).
Use <li data-group> to create labeled sections within the menu. Group labels are non-interactive and visually separated from items. Non-first groups automatically get a top border. On upgrade, each label and the items after it (up to the next label or separator) are wrapped in <li role="group" aria-labelledby> so assistive technology announces the group name; the authored flat list is restored on disconnect, and the items property reads through the wrapper.
Open the menu, with focus on the trigger or on anything inside it
Arrow Down
Move to next item
Arrow Up
Move to previous item
Home
Move to first item
End
Move to last item
Enter / Space
Activate focused item
Escape
Close menu and return focus to the trigger
Tab
Close menu
JavaScript API
Properties
Property
Type
Description
items
Array
Get or replace the menu as data. Entries are { label, value?, href?, shortcut?, disabled? }, { group } or { separator: true }. Setting it rebuilds the menu and fires context-menu:items-changed.
isOpen
boolean
Read-only. Whether the menu is open.
Methods
Method
Description
close()
Close the context menu
Events
Event
Description
context-menu:open
Fired when the menu opens
context-menu:close
Fired when the menu closes
context-menu:select
Fired when an item is activated by click, keyboard or its shortcut. detail.item is the activated element, detail.value its data-value. Not fired for disabled items.
context-menu:items-changed
Fired after the items setter rebuilds the menu (detail: { items, source: 'property' })
Opens from the keyboard: the trigger is made focusable when needed, and Shift+F10 / ContextMenu open the menu while focus is on the trigger or on a control inside it
A trigger that is a control (a button, a link, or a focusable element with a widget role such as role="button") carries aria-haspopup="menu", aria-expanded and aria-controls
Any other trigger, such as a <p>, a <section> or an image, keeps its own semantics and gets no popup state, because screen readers ignore or misreport those states on an element that is not a control. It gets aria-description="Context menu available" instead, so the menu is announced when the trigger takes focus. Change the text with data-label-available on <context-menu>; a trigger that already has aria-description or aria-describedby is left alone
The attributes the component adds to the trigger are removed when it disconnects
Full keyboard navigation (Arrow keys, Home/End, Enter, Escape); focus returns to where it was on close
Menu items have role="menuitem", their <li> wrappers role="none", separators role="separator"
Group labels name a role="group" through aria-labelledby
data-disabled items expose aria-disabled="true" and stay reachable but inert
Keyboard focus shows a focus ring, not only a background tint