You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use tabular numerals for ticking duration and elapsed formats - #392
A ticking format="duration" / format="elapsed" element visibly jumps around as it counts, because proportional digits change width between ticks. The rendered span[part="root"] now gets font-variant-numeric: tabular-nums for those two formats, following the write-skipping pattern of #updateRenderRootContent — the inline style is only written when its value actually changes, so the periodic-tick fast path is untouched.
Other formats get no inline style at all, exactly as before.
The default stays overridable: ::part(root) { font-variant-numeric: normal !important } (an author !important rule beats a non-important inline style).
Of the two shapes discussed in the issue (document a user-side rule vs make it the default), this makes it the default for the ticking formats only — the timer jumping is visible out of the box, while date/relative typography is unchanged.
Verification
npx web-test-runner — 640 passed, 0 failed, including two new tests: one asserts duration and elapsed render with tabular-nums and another asserts other formats get no inline numeric styling; without the change the first fails with expected '' to equal 'tabular-nums'
npx tsc --noEmit and npx eslint src/relative-time-element.ts test/relative-time.js — clean
Addresses #383 by using tabular numerals for ticking duration and elapsed displays, reducing width changes between ticks while leaving other formats’ typography unchanged.
Changes:
Applies numeric styling to span[part="root"], skipping redundant style writes.
Adds tests for tabular timer rendering and the default format’s lack of inline numeric styling.
File
Description
test/relative-time.js
Adds assertions for timer and default-format numeric styling.
src/relative-time-element.ts
Applies or clears tabular numeral styling based on the selected format.
The reason will be displayed to describe this comment to others. Learn more.
Good point — the clearing path was untested. Added in 46fd2a1: a test that renders duration, then switches the same element to auto and asserts the reused span drops tabular-nums. (micro resolves through the same non-duration path, so it is covered by the same branch.) Full suite: 641 passed locally.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The inline numeric styling overrides inherited font features for duration and elapsed, but the README does not document the new default or how to opt out.
Document numeric font variant defaults and opt-out
src/relative-time-element.ts:434
For duration and elapsed, this inline value replaces inherited font-variant-numeric, so existing host or ancestor rules lose features such as oldstyle-nums and slashed-zero. The README's Styling section does not explain this change. Please document the new default and show relative-time::part(root) { font-variant-numeric: normal !important; } as an opt-out.
The build failure was the repo-wide Playwright/Ubuntu 26.04 incompatibility that #394 fixed on main, so I rebased onto main (bfb5b26) — the new runs just need a workflow approval.
I also added a short README section documenting the tabular-numerals default for duration/elapsed and the ::part(root) opt-out, per the review suggestion. npm run lint (tsc + eslint) passes locally.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #383
Description
A ticking
format="duration"/format="elapsed"element visibly jumps around as it counts, because proportional digits change width between ticks. The renderedspan[part="root"]now getsfont-variant-numeric: tabular-numsfor those two formats, following the write-skipping pattern of#updateRenderRootContent— the inline style is only written when its value actually changes, so the periodic-tick fast path is untouched.::part(root) { font-variant-numeric: normal !important }(an author!importantrule beats a non-important inline style).Of the two shapes discussed in the issue (document a user-side rule vs make it the default), this makes it the default for the ticking formats only — the timer jumping is visible out of the box, while date/relative typography is unchanged.
Verification
npx web-test-runner— 640 passed, 0 failed, including two new tests: one assertsdurationandelapsedrender withtabular-numsand another asserts other formats get no inline numeric styling; without the change the first fails withexpected '' to equal 'tabular-nums'npx tsc --noEmitandnpx eslint src/relative-time-element.ts test/relative-time.js— clean