Repository navigation
fix(core): make Timestamp tooltip keyboard-reachable - #4007
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis ReportNo new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | View full report |
humbertovirtudes
left a comment
There was a problem hiding this comment.
Approving. Correct, well-tested a11y fix that follows the repo's existing pattern.
The relative-mode tooltip was pointer-only: useTooltip's auto focus trigger only attaches focus listeners on focusable anchors (useTooltip.tsx:209, 387), and a bare <time> isn't one. Adding tabIndex={0} while a tooltip is attached arms the existing focus path with no change to useTooltip's contract. The tab stop is correctly gated on showTooltip, so absolute formats and hasTooltip={false} add no tab stop. The tabIndex={0} + :focus-visible ring matches the precedent in Tooltip.tsx:295 and Token.tsx.
Tests are solid — the key case (tabbing onto the timestamp reveals the tooltip) is behavior-tested and failed pre-fix.
Two non-blocking notes:
- Every relative
Timestampnow becomes a tab stop. On a dense surface (a feed or table with many "2 hours ago" rows) that adds a lot of tab stops. It's the correct WCAG 1.4.13 remedy and matches the Tooltip text-only behavior, so not a blocker — just worth awareness for high-density lists. - The test file picks up two unrelated Prettier reformats of
rerender(...)calls. Harmless, just outside the scope of the fix.
Summary
Timestampin relative mode (the default for recent times viaformat="auto") exposes the full absolute date/time through aTooltipanchored to its<time>element with the defaultfocusTrigger="auto".useTooltip's auto trigger only attaches focus listeners when the anchor is naturally focusable (useTooltip.tsx:385-393), and a bare<time>is not -- so the tooltip could only ever be revealed with a pointer.Who was affected: the
<time>element already carriesaria-label={fullAbsoluteText}in relative mode (the exact same string the tooltip shows), so screen-reader users were already served. The gap was sighted keyboard users, who saw "2 hours ago" with no keyboard path to the precise time (WCAG 1.4.13 content-on-focus / 2.1.1 keyboard).The fix follows the repo's established pattern for non-interactive tooltip anchors:
Tooltip's own text-only mode makes its wrapper span a tab stop withtabIndex={0}(Tooltip.tsx:295), whichuseTooltip'sisFocusablecheck recognizes (it treats any element with a non-negativetabindexas focusable), so the existingautofocus trigger picks it up.Timestampnow does the same:tabIndex={0}on the<time>element only while a tooltip is attached (hasTooltipand relative display), plus a:focus-visibleoutline matching the repo-wide focus ring treatment (2px solid accent, 2px offset -- same as Token/Thumbnail). No tooltip, no tab stop;useTooltip's contract is untouched. ThefocusTrigger="always"alternative used by disabled-control tooltips (Slider/SelectordisabledMessage) was not needed here -- those anchors are focusable-but-disabled widgets; this one just needed to become a tab stop.Changes
Timestamp/Timestamp.tsx:tabIndex={showTooltip ? 0 : undefined}to the<time>element so the anchor is keyboard-reachable anduseTooltip's existingautofocus trigger attaches focus listeners; a comment explains why the tab stop is conditional.focusableStyleX rule (:focus-visible2px accent outline, 2px offset) applied only alongside the tab stop.Timestamp/Timestamp.test.tsx: newtooltip keyboard reachabilityblock (5 tests) with the same jsdom Popover-API +:focus-visiblemocks used byTooltip.test.tsx/Slider.test.tsx..changeset/timestamp-tooltip-keyboard.md: patch changeset.Test plan
node_modules/.bin/vitest run --root . packages/core/src/Timestamp-- 35 pass (was 30). New tests:<time>hastabindex="0"while the tooltip is attachedshowPopoverfires on keyboard focus) -- failed pre-fix (user.tab()could not land on the non-focusable<time>)tabindexwithhasTooltip={false}-- and the tabindex-present test also failed pre-fixtabindexfor absolute formats (no tooltip, no gratuitous tab stop)node_modules/.bin/vitest run --root . packages/core-- 4586 pass (203 files), no pre-existing failures.node_modules/.bin/tsc --project packages/core/tsconfig.json --noEmit-- clean.node_modules/.bin/eslint+prettier --checkon changed files -- clean.Notes
Found during a broader a11y audit of core components; scoped to one fix per PR (no changes to
useTooltip's contract or other Tooltip consumers).