Skip to content

fix(NumberInput): bound the separator alphabet and read the machine decimal point - #5459

Merged
cixzhang merged 1 commit into
mainfrom
fix-numberinput-bounded-separators
Aug 25, 2026
Merged

cixzhang merged 1 commit into
mainfrom
fix-numberinput-bounded-separators

Conversation

@cixzhang

Copy link
Copy Markdown
Contributor

Fast follow on #5450, which merged (32a62fd) before its review finished. Two blocking defects and one small one are live on main; this fixes all three.

The one decision

#5450 decided which characters may separate digits from the input itself — unbounded for grouping, locale-only for the decimal point. Both halves are wrong, and they are the same decision. This bounds the alphabet and adds the reading the locale could not supply.

utils/dateParser.ts already answers both halves — a literal ([-/.]) separator set and a machine-format branch — and this matches its shape, with one deliberate difference noted below.

B1 — the machine decimal point stopped parsing in comma-decimal locales

Measured in real Chromium, de-DE field, two Storybooks side by side (main @ 32a62fd vs this branch):

BEFORE (main) AFTER
type 1.5 committed 1, no error shown committed 1.5
paste 1.5 refused 1.5
paste 1234.56 refused 1234.56
paste -3.25 refused -3.25
type 1,5 1.5 1.5
paste 1.234 1234 1234

A full stop the locale could not read is not well-formed grouping either, so exactly one reading is left and refusing it lost a number the person typed.

Where dateParser's shape is deliberately not matched: it tries ISO first because 2026-01-25 has no second reading. Here 1.234 in de-DE genuinely has two, and grouping is the one a German means — so the machine reading is tried after the locale reading, not before it. 1.234 → 1234; 1.2345 → 1.2345.

B2 — junk committed as a number

paste, plain en-US field BEFORE AFTER
123-456-789 123456789 refused
1-800-555 1800555 refused
1_234_567 1234567 refused
1/234/567 1234567 refused
1:234:567 1234567 refused

800-555-1212 and 2024-01-15 were refused before only because their last group is the wrong length — luck, not a rule. Now the rule holds: only comma, full stop, the space family, the Swiss apostrophes, the Catalan middle dot, and the Arabic separators count. % gets an asserted corpus row too — 45% is null, deliberately, because the field has no percent semantics.

B3

(+1,234) was -1234 and (-1,234) was +1234 — the paren sign and the leading sign each flipped and composed. An accounting paren already says negative, so a sign inside it reads two ways; both refuse now.

Nothing #5450 got right moved

Same two-sided run, all unchanged: 1,234,234,234 in en-US/de-DE/every locale, 1.234.234.234 de-DE, 1,5 de-DE = 1.5, 1,5 en-US = null, $1,234.56, (1,234), 1,234 GB refused, Arabic-Indic ١,٢٣٤, and the full-width IME composition. All four of #5110's regressions stay cleared, including the role="alert" announcement.

Test plan

  • Every defect above is a corpus row — the corpus is the spec. 102 rows, up from 78.
  • formatEditableNumber had zero tests; it now has explicit rows plus a round-trip assertion over 8 locales × 13 values.
  • pnpm vitest run packages/core/src/NumberInput packages/core/src/utils — 526 passed.
  • Real Chromium, two-sided against main: probe-kit/b1b2b3-two-sided.cjs (24 cases, real insertFromPaste via clipboard + Cmd+V, plus a CDP IME composition). Reviewer's review-shots-5450/parser-battery.mjs re-run clean.

No API change. formatValue untouched. NumberInput.tsx untouched.

@cixzhang

…ecimal point

#5450 decided which characters may separate digits from the input itself:
unbounded for grouping, locale-only for the decimal point. Both halves are
wrong, and they are the same decision.

- A full stop the locale cannot read as grouping now reads as the decimal
  point it can only be, so de-DE 1.5 commits 1.5 again instead of 1. It is
  tried after the locale reading, not before it like dateParser.ts's ISO
  branch, because 1.234 in de-DE genuinely has two readings and grouping is
  the one a German means.
- Only the characters some locale writes between digits are separators, so
  123-456-789 is not 123456789.
- An explicit sign inside accounting parens refuses instead of flipping.

Every defect gets a corpus row, formatEditableNumber gets its first tests.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 25, 2026
@vercel

vercel Bot commented Aug 25, 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 Aug 25, 2026 12:49am

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

NumberInput (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1031 -
Complexity N/A Very High (164) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.8KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

github-actions Bot added a commit that referenced this pull request Aug 25, 2026
@cixzhang
cixzhang merged commit 86c10d7 into main Aug 25, 2026
19 checks passed
cixzhang added a commit that referenced this pull request Aug 25, 2026
…at the parser actually does (#5468)

* fix(NumberInput): drop U+00B7 from the separator alphabet, say what the parser does

Post-merge audit of #5459.

- The file docblock still promised that anything with two readings refuses.
  It does not: where both a grouping and a decimal reading are well formed the
  locale's wins, so de-DE `1.234` is 1234 and `1.2345` is 1.2345. Say so.
- U+00B7 was in the alphabet as the Catalan middle dot. Catalan groups with a
  full stop; walking the 136 locales Intl serves finds no locale that writes a
  middle dot between digits. Remove it and pin the refusal.
- The changeset read as though a structured non-number is now refused. The
  alphabet bounds characters, not shapes: `192.168.100.200` still commits.

Corpus also gains the fr-FR half of the ambiguity rule.

* test(NumberInput): say why the ar-SA editable spelling keeps Latin digits

* fix(NumberInput): make the docblock rule true of readUnder, drop the dead U+00B7 test

Review of #5468.

- The stated rule ignored readUnder's leading-chunk guard, so it got de-DE
  `1234.567` and en-US `1234,567` wrong in both directions. Stated as code it
  disagreed with the parser on 8 of 17 inputs; it now says every group has to
  fit the locale's sizes, and names the cross-locale reading it also omitted.
  probe-kit/numberparser-docblock-rule.mjs: 0 of 35 hand-picked and 0 of 6300
  generated inputs disagree.
- isGroupOnlySeparator still matched U+00B7. Dead — NUMBER_BODY rejects it
  first — but it sat under the paragraph saying the character was removed.
- The sweep behind the alphabet is every language ICU resolves in every
  region, not a hand-written 136. That walk finds a seventh character, U+060C
  (nqo), which the alphabet still leaves out. Wording only.
- The ar-SA row claimed the localized separator is what makes the round trip
  hold. It is not: the plain `String` spelling round trips too. Say the real
  reason — the digits are what the field shows at rest.

* test(NumberInput): land the docblock grader in the repo, and say what it stopped saying

Review round 2 of #5468.

- The rule paragraph under-predicted a space or apostrophe, which groups
  after ONE occurrence: en-US `1 234` is 1234 and the corpus asserts it.
  Add the clause.
- The out-of-repo probe reported zero disagreements because its prediction
  borrowed `isGroupOnlySeparator`'s own rule from the implementation while
  claiming to implement the sentence. A grader that borrows from the thing it
  grades cannot fail. numberParser.docblock.test.ts is derived only from the
  words: each branch names the clause it implements, and those clauses are
  asserted verbatim against the source, so a paragraph that loses one fails
  here. 32,550 generated inputs, zero disagreements.
- "text no reading fits" was missing a "that".

The grader re-derives the locale's symbols from Intl, so it goes on the
no-raw-intl-locale test-oracle allowlist with its own rule test.
@github-actions
github-actions Bot deleted the fix-numberinput-bounded-separators branch August 25, 2026 06:12

This branch was successfully deployed

1 active deployment
Preview — 023f73ff Deployed Aug 25, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant