An open source design system that's fully customizable and agent ready
TypeScript
fix(Timestamp): keep a caller's aria-label and tabIndex (#8726)
Cindy Zhang377ab27fabc8
diff --git a/.changeset/timestamp-caller-name.md b/.changeset/timestamp-caller-name.mdnew file mode 100644index 0000000000..fa3d41875d--- /dev/null+++ b/.changeset/timestamp-caller-name.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] Timestamp keeps a caller's `aria-label` on relative output and a caller's `tabIndex` while its hover card is attached. Before, the full-date name and the card's tab stop overwrote them, so a timestamp named for its context (for example "Posted 5 minutes ago") lost that name, and one taken out of the tab order came back into it. Without a caller value, nothing changes.++@cixzhangdiff --git a/packages/core/src/Timestamp/Timestamp.spec.md b/packages/core/src/Timestamp/Timestamp.spec.mdindex 2edde559d8..b0bbec4193 100644--- a/packages/core/src/Timestamp/Timestamp.spec.md+++ b/packages/core/src/Timestamp/Timestamp.spec.md@@ -44,7 +44,7 @@ system_specs: [spec:AST-009, spec:AST-085]| Behavior | Relative output carries the full absolute date as its default accessible name; relative output, or configured `tooltipEntries`, attach a keyboard-reachable hover card of copyable rows. || End-user impact | Readers see compact or exact times in their locale; screen-reader users hear the full date and time zone; keyboard users can open and copy the exact time. || Builder impact | None; the record describes shipped behavior. |-| Compatibility/readiness | Released behavior recorded as current; no API, default, or output changes. Four implementation gaps are listed under Current-state impact. |+| Compatibility/readiness | Released behavior recorded as current; no API, default, or output changes. Three implementation gaps are listed under Current-state impact. || Review checks | Reject a relative timestamp without the full absolute name when the caller names nothing, a hover card without a tab stop, a change that makes more server markup depend on the server's zone, or a crash on an unparseable value. || Governing rules | `architecture:internationalization/INV4,INV8,INV10`; `architecture:react-component-runtime/INV1,INV3,INV5`; `architecture:public-component-api/INV5,INV6,INV8`. |@@ -70,11 +70,6 @@ Consumer migration instructions belong in consumer docs and release notes.## Current-state impact-- **Caller name and tab stop replaced (FR5, FR9).** On relative output the- full-date name replaces a caller `aria-label`, and while a card is attached- the component's `tabIndex={0}` replaces a caller `tabIndex`, where- `architecture:public-component-api` INV5 lets a caller's explicit input reach- the element.- **Focus lost when the card attaches (FR6, AR3).** While the card moduleloads, a fallback `time` with the tab stop renders; when the card attaches itreplaces that element, so keyboard focus placed on it falls to the page body@@ -129,11 +124,11 @@ Consumer migration instructions belong in consumer docs and release notes.| FR2 | `auto` shows `relative` when the instant is within `autoThreshold` seconds of now (default seven days) and `date_time` otherwise. `relative` uses the locale's long relative phrase and `relative_short` its narrow phrase; a value a few seconds in the future reads as "now". Absolute formats use the shared instant formatter in the provider locale with Gregorian years; `system_*` formats are machine-readable, and `unix_seconds` is zone-independent. `isTimezoneShown` appends the zone abbreviation to `date_time` and `time` only. | Current source and tests || FR3 | Server markup does not depend on the server's time zone and hydrates without a mismatch. A format that needs the clock renders `date_time` in UTC with the zone shown until the client can read the clock; the client then shows the resolved format without committing the UTC placeholder. Implementation gap: absolute formats other than `unix_seconds` render in the host's time zone, so their server markup depends on the server's zone and hydrating it in another zone produces a text mismatch (Current-state impact). | Current source and tests || FR4 | With `isLive` and relative output, the clock refreshes every second under a minute old, every 30 seconds under an hour, every minute under a day, and every five minutes beyond; the timer is cleared on unmount or when the inputs change. Locale changes update the output live. | Current source and tests |-| FR5 | Relative output is named by the full absolute date and the long time-zone name unless a caller names the element; absolute output adds no name. A caller's explicit `aria-label` reaches the element (`architecture:public-component-api` INV5). Implementation gap: the component's full-date name replaces a caller `aria-label` on relative output (Current-state impact). | Current source and tests |+| FR5 | Relative output is named by the full absolute date and the long time-zone name unless a caller names the element; absolute output adds no name. A caller's explicit `aria-label` reaches the element (`architecture:public-component-api` INV5). | Current source and tests || FR6 | When `hasTooltip` is true and the output is relative or `tooltipEntries` is non-empty, a lazily loaded HoverCard named "Timestamp details" attaches above the timestamp, opening on hover and on keyboard focus; the `time` element gains `tabIndex={0}`. Otherwise no card renders and no tab stop is added. Focus placed on the timestamp stays there when the card attaches (`spec:AST-085` FR4). Implementation gap: while the card module loads, a fallback `time` with the tab stop renders, and attaching the card replaces it, so focus placed on it falls to the page body and no card opens (Current-state impact). | Current source and tests || FR7 | The card is a description list in a grid: an optional label column (present when any row has a label), the value column, and a trailing action column (present when any row is copyable). Without entries it has one copyable row with the full absolute time in the viewer's zone. Each configured entry is one row in the given order, rendered in its own time zone and format, read-only unless `isCopyable`. An unknown time zone does not crash. A description list holds only name-value groups (WCAG 2.2 1.3.1). Implementation gaps: once any row is copyable, every row carries an action-cell `div` inside its row group (empty on read-only rows), so the open card fails the `definition-list` structure check, and a card with no labelled rows, the default card included, renders each row as a lone `dd` with no `dt` (Current-state impact). | Current source and tests || FR8 | A copy button is a small ghost IconButton on the `timestamp-copy-button` target, named "Copy {value}" with a "Copy" tooltip; activating it writes the row's value to the clipboard, switches to a check icon and the "Copied" name and tooltip for 1.5 seconds, and announces "Copied" politely. A clipboard rejection does nothing. | Current source and tests |-| FR9 | `ref`, `data-testid`, and other supported DOM, ARIA, data, and event props reach the `time` element; `xstyle`, `className`, and `style` reach the Text wrapper. A caller `aria-labelledby` names the element in place of FR5's name. A caller's explicit `tabIndex` reaches the element (`architecture:public-component-api` INV5). Implementation gap: while a card is attached, the component's `tabIndex={0}` replaces a caller `tabIndex` (Current-state impact). | Current source and tests |+| FR9 | `ref`, `data-testid`, and other supported DOM, ARIA, data, and event props reach the `time` element; `xstyle`, `className`, and `style` reach the Text wrapper. A caller `aria-labelledby` names the element in place of FR5's name. A caller's explicit `tabIndex` reaches the element (`architecture:public-component-api` INV5). | Current source and tests |### Allowed variation@@ -161,8 +156,7 @@ Consumer migration instructions belong in consumer docs and release notes.- **ORD2 — Card rows.** Non-empty `tooltipEntries` → the default full-date row.- **ORD3 — Time element attributes.** `datetime` and `data-testid` are set,then caller props; the relative name and the card's tab stop apply only- where the caller sets no `aria-label` or `tabIndex` (today they overwrite- the caller's, the FR5 and FR9 gaps).+ where the caller sets no `aria-label` or `tabIndex`.### Performance and resources@@ -230,10 +224,10 @@ Consumer migration instructions belong in consumer docs and release notes.| FR1, FR2 | `Timestamp.test.tsx` format, auto, locale, and invalid-value tests; stable visual baseline `core-timestamp--default` | Every format; thresholds; locales; unparseable values; default | A wrong phrase, a crossed tier, a non-Gregorian year, a missing `time` element or `datetime`, a crash, or a missing development warning for an unparseable value fails; a changed default type or color comes back changed for review. Gap: no test asserts the `timestamp` target or its format reflection. | `audit:Timestamp/behavior` || FR3 | `Timestamp.test.tsx` server-rendering suite | Server zones; hydration | Zone-dependent markup, a hydration mismatch, or a committed placeholder fails. Gap: no test covers an absolute format rendered on a server in another zone. | `audit:Timestamp/behavior` || FR4, PR1 | `Timestamp.test.tsx` live-update and locale tests | Live relative output; locale change | A missing refresh or a stale locale fails. Gap: the per-tier refresh intervals and the timer cleanup on unmount or input change have no automated check. | `audit:Timestamp/behavior` |-| FR5, AR2 | `Timestamp.test.tsx` naming tests | Relative, absolute, time-zone spelling | A missing or short-zone name, or a name on absolute output, fails. The pass-through test "keeps its own spelled-out label on a relative timestamp" pins the caller-`aria-label` replacement, which is the recorded gap, not the contract. | `audit:Timestamp/a11y` |+| FR5, AR2 | `Timestamp.test.tsx` naming tests | Relative, absolute, time-zone spelling | A missing or short-zone name, or a name on absolute output, fails. A caller `aria-label` replaced on relative output fails. | `audit:Timestamp/a11y` || FR6, AR3 | `Timestamp.test.tsx` keyboard-reachability suite | Relative, absolute, disabled, entries removed | A missing tab stop, `aria-expanded` on the trigger, or a stray tab stop fails. The aria-expanded test also pins `aria-haspopup` on the Text wrapper, which is current behavior, not contract. Gap: no test covers focus on the timestamp while the card module loads, or `aria-controls`. | `audit:Timestamp/a11y` || FR7, FR8, AR4 | `Timestamp.test.tsx` hover-card suites; `tooltipEntries.test.ts`; `useClipboard.test.tsx` | Default row, entries, copyable rows, unknown zone | A wrong row count or order, an unpaired label, a copy button on a read-only row, a wrong copied value, a missing copied state, or a missing announcement fails. Gap: no check runs the `definition-list` structure rule on the open card (the recorded gap); the grid columns and the 1.5-second reset have no automated check; `useClipboard.test.tsx` covers the clipboard-rejection no-op. The lone-`dd` rows of a label-less card are also unchecked. | `audit:Timestamp/behavior` |-| FR9 | `Timestamp.test.tsx` ref, test-id, and pass-through tests | Ref, test id, caller props | A ref, test id, or caller prop missing from the `time` element fails. Gap: no test asserts that `xstyle`, `className`, and `style` reach the Text wrapper, or covers a caller `aria-labelledby` or `tabIndex`. | `audit:Timestamp/behavior` |+| FR9 | `Timestamp.test.tsx` ref, test-id, and pass-through tests | Ref, test id, caller props | A ref, test id, or caller prop missing from the `time` element fails. A caller `tabIndex` replaced while a card is attached fails. Gap: no test asserts that `xstyle`, `className`, and `style` reach the Text wrapper, or covers a caller `aria-labelledby`. | `audit:Timestamp/behavior` || Theming anatomy map | `scripts/check-knowledge.mjs` | Consumer anatomy, targets, HoverCard delegate | Missing, extra, or stale mappings fail repository validation. | `audit:Timestamp/theming` || AR1 | `Timestamp.test.tsx` `datetime` tests | `date_time`; `date` | A missing or wrong ISO `datetime` on `date_time`, or a missing one on `date`, fails. Gap: no test asserts the exact `datetime` on relative or other absolute formats. | `audit:Timestamp/a11y` || AR2, AR4 | Accessibility-tree evidence (`spec:AST-009` FR3) | Relative output; copy buttons | Gap: no accessibility-tree check proves the computed name of relative output or the copy-button names; the unit tests query the DOM. | `audit:Timestamp/a11y` |diff --git a/packages/core/src/Timestamp/Timestamp.test.tsx b/packages/core/src/Timestamp/Timestamp.test.tsxindex de1b623a51..51ae76ab4c 100644--- a/packages/core/src/Timestamp/Timestamp.test.tsx+++ b/packages/core/src/Timestamp/Timestamp.test.tsx@@ -768,6 +768,20 @@ describe('Timestamp', () => {HTMLElement.prototype.hidePopover = originalHidePopover;});+ it("keeps a caller's tabIndex while the hover card is attached (FR9)", async () => {+ render(+ <Timestamp+ value={Date.now() / 1000 - 3600}+ format="relative"+ tabIndex={-1}+ data-testid="ts"+ />,+ );+ expect(screen.getByTestId('ts')).toHaveAttribute('tabindex', '-1');+ await openTimestampHoverCard();+ expect(screen.getByTestId('ts')).toHaveAttribute('tabindex', '-1');+ });+it('makes the <time> element focusable while the hover card is attached', () => {render(<Timestamp@@ -1449,7 +1463,7 @@ describe('Timestamp pass-through props', () => {expect(time).toHaveAttribute('data-source', 'cms');});- it('keeps its own spelled-out label on a relative timestamp', () => {+ it("keeps a caller's aria-label on a relative timestamp (FR5)", () => {render(<Timestampvalue={Date.now()}@@ -1463,10 +1477,21 @@ describe('Timestamp pass-through props', () => {expect({ariaLabel: stamp.getAttribute('aria-label'),dataSource: stamp.getAttribute('data-source'),- }).toEqual({- ariaLabel: expect.not.stringMatching(/^Caller label$/),- dataSource: 'cms',- });+ }).toEqual({ariaLabel: 'Caller label', dataSource: 'cms'});+ });++ it('names a relative timestamp by the full date when the caller names nothing (FR5)', () => {+ render(+ <Timestamp+ value={Date.now()}+ format="relative"+ aria-label={undefined}+ data-testid="stamp"+ />,+ );+ expect(screen.getByTestId('stamp').getAttribute('aria-label')).toMatch(+ /\d{4}/,+ );});});diff --git a/packages/core/src/Timestamp/Timestamp.tsx b/packages/core/src/Timestamp/Timestamp.tsxindex 2f87e66d72..6cb84f8565 100644--- a/packages/core/src/Timestamp/Timestamp.tsx+++ b/packages/core/src/Timestamp/Timestamp.tsx@@ -443,7 +443,10 @@ export function Timestamp({// before rendering — but keep the guard local: an empty aria-label// must be omitted entirely (not rendered as aria-label="") so AT// falls back to reading the visible <time> content.- {...(isRelativeFormat(effectiveFormat) && ariaLabelText !== ''+ // A caller's own name wins (`component:Timestamp` FR5).+ {...(isRelativeFormat(effectiveFormat) &&+ ariaLabelText !== '' &&+ rest['aria-label'] == null? {'aria-label': ariaLabelText}: {})}// The hover card is anchored here with focusTrigger="always", which@@ -454,7 +457,8 @@ export function Timestamp({// gratuitous tab stops otherwise. The card carries its own// dashed-underline hover indication as the affordance, so the anchor// needs no separate focus outline.- {...(showTooltip ? {tabIndex: 0} : {})}>+ // A caller's own tabIndex wins (`component:Timestamp` FR9).+ {...(showTooltip && rest.tabIndex == null ? {tabIndex: 0} : {})}>{displayText}</time></Text>