Set false to skip making the element keyboard-focusable (rare; e.g. focus handled elsewhere).
Accessible name for the control, surfaced as aria-label. Pass the human-meaningful label
(e.g. the app/nav-item name). Strongly recommended — without it the control is operable but
unnamed, so agents/AT can reach it but can't identify it. When omitted, the element's own
visible text becomes the name (fine when the text alone is unambiguous).
ARIA role to expose. 'button' (default) for actions, 'link' for navigation-like targets.
OptionaltestOptional stable automation/test hook emitted as data-testid (no convention enforced here).
Dev-only guard: warn when the control ends up with no accessible name. No-op in production.
Keyboard activation: Enter / Space activate a role="button"/"link" exactly as they would a
native control. We preventDefault (Space would otherwise scroll the page) and dispatch a native
click, so the element's existing (click) binding handles both mouse and keyboard with no
duplicate wiring.
mjClickable — Attribute directive that upgrades a non-semantic element (a
<div>/<span>that has a(click)handler) into a proper, accessible, keyboard-operable control without changing its tag or styling.Why this exists
A
<div (click)="…">is invisible as a control to anyone (and anything) that consumes the accessibility tree rather than pixels:role=genericwith no accessible name.Converting such a
<div>to a native<button>is the ideal fix, but often forces CSS churn for already-styled tiles/rows.mjClickableis the low-risk alternative: it keeps the element and its styles, and adds the missing semantics —role,tabindex, an accessible name (aria-label), Enter/Space activation (which dispatches a nativeclick, so your existing(click)handler runs for both mouse and keyboard), and an optional stabledata-testidautomation hook.Prefer a real
<button mjButton>/<a>for NEW markup; reach formjClickableto retrofit existing clickable<div>/<span>widgets (nav tiles, list rows, cards) cheaply.Example