fix(ui): keep the gap between date and time segments in every locale - #16794
fix(ui): keep the gap between date and time segments in every locale#16794thomassarazin wants to merge 2 commits into
Conversation
The literal segment between the date and the time was only special-cased when its text is the en-US ", ". In fr-FR and many other locales that literal is a lone " ", rendered as a whitespace-only text node that the browser collapses at the line edge: the date and the time were glued together (09/09/202609:05). Any literal whose trimmed text is empty now takes the same spacing span. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0135G2otNMNJ8kQ9Gk7wzsqo
🦋 Changeset detectedLatest commit: 066f158 The changes in this PR will be included in the next version bump. This PR includes changesets to release 83 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Thanks for the contribution! A few items need to be addressed before this can move forward: The contributor fixes missing spacing between the date and time segments of DatePicker in non-English locales. The approach is to widen the literal-segment check from the exact string ", " to any literal whose trimmed text is empty. A changeset (correct patch bump, correct fix(ui): format) and a parametrised test covering en-US and fr-FR are included. There is a correctness problem with the condition. ", ".trim() evaluates to "," — the comma is not whitespace, so it is not stripped, and the result is non-empty. The new condition segment.text.trim() === "" therefore does NOT match the en-US ", " separator. In real browsers where the date–time literal is ", " (as the original code was explicitly written to handle, and as the test's own block comment states), the new code falls through to the default branch and renders ", " as visible text inside a <div>, losing the mx-1 spacing span — a regression for English-locale users. The test most likely passes because the jsdom environment does not accurately replicate locale-aware ICU formatting, making the en-US assertion a false positive rather than genuine coverage of real-browser behaviour.
Triggered by: new PR opened |
", ".trim() is ",", so the widened condition dropped the original en-US case. The spacing span now applies to the ", " literal as before and to whitespace-only literals. The test asserts that no separator survives as text, which fails for en-US with the previous condition and for fr-FR with the original code. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0135G2otNMNJ8kQ9Gk7wzsqo
|
Good catch, thank you.
One side effect worth noting: the |
|
Thanks for the contribution! Initial automated review looks good. The contributor fixes a locale-specific visual bug in the DatePicker component where the date and time segments were rendered without a gap in non-English locales (e.g., fr-FR, de-DE). The root cause was that the original code only matched the en-US literal separator ", ", while other locales emit a bare " " (space-only) which the browser collapses, causing the two groups of digits to touch. A previous review flagged a logic error in the first attempt — ", ".trim() evaluates to "," (non-empty), so the en-US case was inadvertently dropped. The author addressed this correctly: the condition now reads segment.text === ", " || segment.text.trim() === "", which preserves the original en-US branch and adds handling for space-only separators. The fix also benefits 12-hour locales where a " " before AM/PM was also rendered as a collapsing text node. The test covers both en-US and fr-FR, asserting that a spacing span exists and that no leaf div contains ", " or non-empty whitespace-only text. The logic is sound and correctly distinguishes the two cases. Checklist: PR template complete, changeset included with correct patch bump and fix(ui): format, tests added, no issue/PR references in code comments, no security or performance concerns. Triggered by: new commit pushed |
Summary
What — In
@medusajs/ui, aDatePickerwith a time granularity renders the date glued to the time in French and in many other locales:09/09/202609:05instead of09/09/2026 09:05. This PR keeps the gap whatever the locale.Why —
DateSegmentspecial-cases the literal segment between the date and the time, but only when its text is the en-US", ": that literal is replaced by an empty<span className="mx-1" />, which is what produces the visible gap. In fr-FR (and de-DE, es-ES, it-IT, nl-NL…),Intl.DateTimeFormatemits a lone" "as that literal. It falls through to the generic branch and is rendered as a text node made only of whitespace, which the browser collapses at the line edge. The gap disappears and the two groups of digits touch. The admin dashboard shows this on every date-with-time field (price list start and end dates, campaign dates, scheduled publishing) as soon as the browser language is not English.How — The special case now applies to the en-US
", "literal as before and to any literal whose trimmed text is empty, so the space used by the other locales takes the same spacing span. One condition changed, no new prop, no layout change for en-US.Testing — Added
date-segment.spec.tsx: renders aDatePickerwithgranularity="minute"underI18nProviderin en-US and fr-FR, and asserts that a spacing span exists and that no separator survives as text (no leaf node equal to", ", none made only of whitespace). Node's ICU honours the locale here (formatToPartsgives", "for en-US and" "for fr-FR). The fr-FR case fails on the original code and passes after the fix; the en-US case guards against dropping the comma branch. Also verified manually on a 2.15.5 admin with the browser in French: price list dates read09/09/2026 09:05after the fix. Bug reproduced ondevelopas well.Examples
Checklist
Additional Context
Found while scheduling sales on a French store: the start and end dates of a price list were unreadable in the admin.
🤖 Generated with Claude Code
https://claude.ai/code/session_0135G2otNMNJ8kQ9Gk7wzsqo