Skip to content

Contexts

Contexts sit on top of the toggle foundation and orchestrate everything a composite pattern needs: ARIA semantics, behavioral wiring, and alias normalization. Attach a single data-automagica11y-context attribute to a toggle trigger and the registry keeps the trigger, target, and any aliases in sync.

  1. Start with a toggle. Every context begins as a data-automagica11y-toggle trigger connected to a target surface.
  2. Opt into shared semantics. Add data-automagica11y-context="dialog" (or any alias) and the registry applies the appropriate roles and ARIA attributes.
  3. Layer behaviors on demand. Context modes decide whether to hydrate focus traps, hover intent, inert locking, and other helpers. Behaviors always piggyback on the same toggle lifecycle events that plugins use.
  4. Compose freely. Multiple contexts can coexist on a page. They emit namespaced events (automagica11y:dialog:*, automagica11y:tooltip:*) so plugins and analytics stay coordinated.
Toggle-first mental model

Because contexts reuse toggle internally, everything you learn in the Toggle pattern applies here too: truthiness aliases, grouped triggers, and lifecycle events all behave identically.

AttributeDescription
data-automagica11y-contextNames the context to activate (for example dialog, tooltip, menu).
data-automagica11y-targetSelector for the managed surface. Defaults to the next sibling or the resolved ID.
data-automagica11y-context-modeControls automation depth. Accepts all (default), semantics-only, or behaviors-only.
data-automagica11y-context-aliasOverride the alias mapping for bespoke vocabulary.
  • all – semantics + behaviors (default).
  • semantics-only – apply ARIA/role defaults only; wire your own behaviors.
  • behaviors-only – reuse dismissal, focus traps, and state syncing without altering existing semantics.
ContextSemanticsBehaviorsExamplesPattern docs
dialogrole="dialog", aria-modal, trigger linkingFocus trap, inert siblings, Escape to close, restore focusContext dialogDialog pattern
tooltiprole="tooltip", aria-describedby wiringHover intent, long-press, anchor followContext tooltipTooltip pattern
menurole="menu" scaffoldingBehaviors planned (roving tabindex, typeahead)RoadmapToggle pattern
accordionrole="region" scaffoldingBehaviors plannedRoadmapToggle pattern
disclosurerole="region" scaffoldingBehaviors plannedRoadmapToggle pattern
listboxrole="listbox" scaffoldingBehaviors plannedRoadmapToggle pattern
tablistrole="tablist" scaffoldingBehaviors plannedRoadmapToggle pattern
treerole="tree" scaffoldingBehaviors plannedRoadmapToggle pattern

Use the matrix to decide whether a context already automates the behaviors you need or whether you should augment it with plugins today. The @core/context/registry.ts reference page lists the same capabilities at the source level.

AliasCanonical context
dropdown, kebab, meatballmenu
modal, dialog, sheetdialog
details, expander, disclosuretoggle
tooltip, hint, labeltooltip

Aliases keep older attribute names and regional terminology working while still running through the same context pipeline.

The legacy data-automagica11y-dialog attribute maps directly to the dialog context.

Context vs. alias

Two ways to activate the same dialog wiring.

View source

Tooltips share the same alias wiring.

Context vs. tooltip alias

Context and alias both hydrate tooltip behavior.

View source

The context registry evolves alongside the core patterns. Track progress in the Examples roadmap and the Core reference:

  • Menu context behaviors – roving tabindex, typeahead search, and dismissible submenus.
  • Accordion & disclosure parity – share toggle grouping logic, add aria-disabled and single-open coordination.
  • Listbox, tablist, and tree – mirror WAI-ARIA Authoring Practices with arrow key navigation and typeahead.
  • Context capability lab – interactive demo that lets you toggle focus trap, inert siblings, hover intent, and anchor follow helpers individually.

As each milestone lands, the matrix above and the associated pattern pages will note the new capabilities.