Skip to content

fix(core): make Timestamp tooltip keyboard-reachable - #4007

Merged
humbertovirtudes merged 1 commit into
meta:mainfrom
bhamodi:a11y/timestamp-tooltip-keyboard
Jul 15, 2026
Merged

humbertovirtudes merged 1 commit into
meta:mainfrom
bhamodi:a11y/timestamp-tooltip-keyboard

Conversation

@bhamodi

@bhamodi bhamodi commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Timestamp in relative mode (the default for recent times via format="auto") exposes the full absolute date/time through a Tooltip anchored to its <time> element with the default focusTrigger="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 carries aria-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 with tabIndex={0} (Tooltip.tsx:295), which useTooltip's isFocusable check recognizes (it treats any element with a non-negative tabindex as focusable), so the existing auto focus trigger picks it up. Timestamp now does the same: tabIndex={0} on the <time> element only while a tooltip is attached (hasTooltip and relative display), plus a :focus-visible outline 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. The focusTrigger="always" alternative used by disabled-control tooltips (Slider/Selector disabledMessage) was not needed here -- those anchors are focusable-but-disabled widgets; this one just needed to become a tab stop.

Changes

  • Timestamp/Timestamp.tsx:
    • add tabIndex={showTooltip ? 0 : undefined} to the <time> element so the anchor is keyboard-reachable and useTooltip's existing auto focus trigger attaches focus listeners; a comment explains why the tab stop is conditional.
    • add a focusable StyleX rule (:focus-visible 2px accent outline, 2px offset) applied only alongside the tab stop.
  • Timestamp/Timestamp.test.tsx: new tooltip keyboard reachability block (5 tests) with the same jsdom Popover-API + :focus-visible mocks used by Tooltip.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> has tabindex="0" while the tooltip is attached
    • tabbing onto the timestamp shows the tooltip (lazy layer mounts, carries the aria-label string, showPopover fires on keyboard focus) -- failed pre-fix (user.tab() could not land on the non-focusable <time>)
    • no tabindex with hasTooltip={false} -- and the tabindex-present test also failed pre-fix
    • no tabindex for absolute formats (no tooltip, no gratuitous tab stop)
    • aria-label still the full absolute string while the tooltip is attached
  • 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 --check on 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).

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 15, 2026
@vercel

vercel Bot commented Jul 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview, Comment Jul 15, 2026 3:07pm

Request Review

@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Jul 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.6KB 0B

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | View full report

@humbertovirtudes humbertovirtudes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Timestamp now 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.

@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Jul 15, 2026
@humbertovirtudes
humbertovirtudes merged commit eba4f34 into meta:main Jul 15, 2026
20 checks passed
@github-actions
github-actions Bot deleted the a11y/timestamp-tooltip-keyboard branch July 16, 2026 07:59

This branch was successfully deployed

1 active deployment
Preview — b1f02be5 Deployed Jul 15, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants