Repository navigation
Description
Summary
Make Avatar optionally interactive — support href and onClick so an avatar can be a link (to a profile) or a button (open a menu/dialog). When interactive avatars are inside an AvatarGroup, the group should be a single tab stop with roving arrow-key navigation via useListFocus (with a keyboard hint), rather than N separate tab stops.
Motivation
Today Avatar renders a static <div role="img"> — no way to make it clickable without a consumer wrapping it in their own <a>/<button>, which loses the component's styling, focus ring, and a11y wiring. Profile avatars that navigate, or avatars that open an actions menu, are extremely common. Avatar should own this the same way Button does.
And when a row of avatars is interactive, tabbing through every single one is poor keyboard UX. Composite widgets should be one tab stop with arrow-key navigation — the pattern useListFocus({hasRovingTabIndex: true}) already implements.
Proposed behavior
Avatar (interactive mode)
href+as→ renders as a link, usinguseLinkComponent()for the app's router (same precedent asButton:href,as: LinkComponentType,target,rel).onClick→ renders as a<button>when nohref.- Neither → stays the current static
<div role="img">(no behavior change, no focusability). - Interactive avatars get the correct role, keyboard activation (Enter/Space for button, Enter for link), a visible
:focus-visiblering, and hover/active affordances.name/altremains the accessible name (coordinate with the default-tooltip work in Avatar: show name tooltip by default, auto-disable when wrapped in a tooltip/hovercard #4164). - Follows the same "component wins on contract props, compose consumer handlers via
composeEventHandlers" forwarding rules as the rest of core.
AvatarGroupOverflow (interactive parity)
- The "+N" indicator already renders as a
<button>whenonClickis passed, but has no link support. Give it the same interactive contract as Avatar: addhref+as(viauseLinkComponent) so "+N" can navigate (e.g. to a full member list), keeponClickfor the button case, and stay a static<span>when neither is provided. - Same role/keyboard/focus-ring/activation treatment as an interactive Avatar, and it participates in the group's roving tab order (below).
AvatarGroup (single tab stop)
- When its avatars are interactive, AvatarGroup uses
useListFocuswithhasRovingTabIndex: trueso the group is one tab stop: one avatar istabindex="0", the rest-1, and Left/Right (horizontal orientation) move focus, with Home/End for boundaries. The hook already stamps/repairs the roving tab stop as items mount/unmount. - The
AvatarGroupOverflow"+N" indicator participates in the roving order when it's interactive (onClickorhref). - Keyboard hint: surface a hint that the group is arrow-navigable (e.g. an
aria-description/visually-hidden instruction, or a documented pattern) so screen-reader and keyboard users know to use arrows. (Exact hint mechanism is a spec question — see below.) - Correct container semantics (the group already has
role="group"+ label; may need to move toward a listbox/toolbar-style role depending on whether avatars are links vs buttons).
Design notes / open questions (for spec)
- Reuse, don't reinvent.
Buttonalready solves link-vs-button rendering (href/as/useLinkComponent,aria-disabledfocus handling) anduseListFocusalready solves the single-tab-stop roving pattern (hasRovingTabIndex, orientation, Home/End, RTL). This should compose those, not duplicate them. Consider whether the interactive shell should come from the sharedClickableprimitive proposed in Add generic Clickable and ClickableContainer components #3704. - Role choice in a group: a group of link-avatars vs button-avatars implies different container semantics (navigation list vs toolbar). Spec should pin this to a WAI-ARIA pattern.
- Hint delivery: decide between a visually-hidden instruction,
aria-description, or relying on the roving pattern alone. Don't double-announce. - Non-interactive avatars in a mixed group — define behavior when only some avatars are interactive.
Contract additions (relevant to #4163)
- Avatar:
href?,as?: LinkComponentType,target?,rel?,onClick?— new public props to spec + document, mirroring Button's link props. - AvatarGroup: any prop needed to opt into roving focus (or infer it from interactive children) + the hint.
- AvatarGroupOverflow: add
href?,as?: LinkComponentType,target?,rel?(it already hasonClick?) — mirror Avatar's link props.
Acceptance criteria
-
<Avatar href="/u/jane" name="Jane" />renders a link (viauseLinkComponent), keyboard-activatable, with a focus ring. -
<Avatar onClick={…} name="Jane" />renders a focusable button with Enter/Space activation. -
<Avatar name="Jane" />(neither) is unchanged — staticrole="img", not focusable. - An
AvatarGroupof interactive avatars is a single tab stop; Left/Right move focus between them; Home/End jump to ends. -
AvatarGroupOverflowsupportshref(renders a link viauseLinkComponent) as well asonClick, and stays a static<span>when neither is set. - Interactive
AvatarGroupOverflow(link or button) participates in the roving order. - A keyboard/AT hint communicates arrow-navigation; accessible name is not double-announced.
- Non-interactive avatars unaffected; mixed groups behave per spec.
- Works across themes + light/dark; focus ring visible in both.
Notes
- New API surface + a11y pattern → spec protocol first (Component Lifecycle).
- Avatar family: Avatar: show name tooltip by default, auto-disable when wrapped in a tooltip/hovercard #4164 (default tooltip), IconButton: show label tooltip by default, allow disabling/overriding (mirror Avatar #4164) #4165 (IconButton tooltip), AvatarGroupOverflow: grow to a pill for long counts so "+N" text doesn't clip #4167 (overflow pill). Tooltip + interactivity interact — an interactive avatar's tooltip suppression rules (Avatar: show name tooltip by default, auto-disable when wrapped in a tooltip/hovercard #4164) should be consistent here.
Activity
feat(Avatar): optional href/onClick interactivity + roving focus in A…
feat(Avatar): optional href/onClick interactivity + roving focus in A…
feat(Avatar): optional href/onClick interactivity + roving focus in A…
feat(Avatar): optional href/onClick interactivity + roving focus in A…