Skip to content

[number field] Fix keyboard editing with multi-character format symbols - #5111

Merged
atomiks merged 4 commits into
mui:masterfrom
atomiks:claude/inspiring-torvalds-5b2d1f
Jun 29, 2026
Merged

atomiks merged 4 commits into
mui:masterfrom
atomiks:claude/inspiring-torvalds-5b2d1f

Conversation

@atomiks

@atomiks atomiks commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Closes #5107

Problem

A NumberField whose Intl format produces a multi-character symbol could not be edited by typing — every keystroke was silently rejected, the text reverted, and the caret jumped to the end. The reported case is pt-BR currency (R$ 1.234,56), but the same flaw affected any multi-character or non-enumerated decoration:

format locale displayed typing before after
{ style: 'currency', currency: 'BRL' } pt-BR R$ 1.234,56 ❌ ✅
{ style: 'unit', unit: 'kilometer-per-hour' } en-US 12 km/h ❌ ✅
{ notation: 'scientific' } en-US 1.5E3 ❌ ✅
{ notation: 'scientific' } fa-IR ۱×۱۰^‎−۱ ❌ ✅
{ style: 'currency', currency: 'USD' } en-US $1,234.56 ✅ ✅

Cause

getAllowedNonNumericKeys added the currency symbol to the allowed set as a whole string (keys.add(currency) → "R$"), but the input's change handler validates the typed text one character at a time (allowedNonNumericKeys.has(ch)). "R" and "$" were never in the set, so the whole value failed validation and the edit was reverted. Single-character symbols like $ happened to work because the set entry matched the single char; units and exponent separators were never added at all.

Fix

  1. Derive the allowed characters from Intl.NumberFormat.formatToParts, per character. This covers multi-character and locale-specific symbols of every part type uniformly (currency, unit, exponent separator, literals) and replaced the previous per-symbol currency/literal/group branches. compact suffixes (K/M) are intentionally excluded — parseNumber can't reverse them (11K → 11), so allowing them would produce silently-wrong values.

  2. Ignore Unicode format/bidi controls (\p{Cf}) in the validator. RTL locales insert marks such as U+200E around the exponent sign in scientific notation, and parseNumber already strips them, so the validator must treat them as ignorable rather than discarding the keystroke.

Also extracted the shared 11111.1 sample (already used by getNumberLocaleDetails) into a getFormatParts helper so both derivations enumerate the same parts.

Testing

Added tests for the currency (issue repro), unit, scientific-notation, and RTL-scientific (fa-IR, with bidi controls) cases — each confirmed to fail before the fix. Existing input-masking tests still pass. Full NumberField suite passes in jsdom and Chromium (the issue was browser-confirmed).


@atomiks atomiks added component: number field Changes related to the number field component. type: bug It doesn't behave as expected. labels Jun 24, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@5111
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@5111
    

commit: 331036f

@code-infra-dashboard

code-infra-dashboard Bot commented Jun 24, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+155B(+0.03%) 🔺+36B(+0.02%)

Details of bundle changes

Performance

Total duration: 1,337.87 ms -57.52 ms(-4.1%) | Renders: 78 (+0)

Test Duration Renders
Mixed surface mount (app-like density) 95.56 ms 🔺+20.36 ms(+27.1%) 5 (+0)
Tooltip mount (300 contained roots) 53.37 ms ▼-16.00 ms(-23.1%) 1 (+0)

12 tests within noise — details

Metric alarms

Test Metric Change
Mixed surface mount (app-like density) bench:paint 🔺 +23.85 ms

Check out the code infra dashboard for more information about this PR.

@atomiks
atomiks force-pushed the claude/inspiring-torvalds-5b2d1f branch from b184097 to 6345cb6 Compare June 24, 2026 04:58
@atomiks atomiks changed the title [number-field] Fix keyboard editing with multi-character format symbols [number field] Fix keyboard editing with multi-character format symbols Jun 24, 2026
@netlify

netlify Bot commented Jun 24, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit b184097
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a3b6339f7f4280008c9146a
😎 Deploy Preview https://deploy-preview-5111--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Jun 24, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 331036f
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a42133fe4c9250009bf0f86
😎 Deploy Preview https://deploy-preview-5111--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks
atomiks force-pushed the claude/inspiring-torvalds-5b2d1f branch 2 times, most recently from 6566700 to bf53a5a Compare June 24, 2026 05:37
Currency symbols longer than one character (e.g. pt-BR BRL `R$`), units (`km/h`, `°C`), and scientific notation could not be edited by typing: the allowed-key set added these symbols as whole strings, but the input validates the typed text character by character, so every keystroke was rejected.

Derive the allowed non-numeric characters from `Intl.NumberFormat.formatToParts` and decompose them per character, which covers multi-character and locale-specific symbols of every part type uniformly. `compact` suffixes stay excluded because `parseNumber` can't reverse them.

Also stop the input validator from rejecting Unicode format/bidi controls (`\p{Cf}`): RTL locales insert marks such as U+200E around the exponent sign in scientific notation, and `parseNumber` already strips them, so the validator must treat them as ignorable rather than discarding the keystroke.

Fixes mui#5107.
@atomiks
atomiks force-pushed the claude/inspiring-torvalds-5b2d1f branch from bf53a5a to 7949988 Compare June 24, 2026 05:38
@atomiks
atomiks marked this pull request as ready for review June 24, 2026 05:45
@atomiks
atomiks requested a review from Copilot June 29, 2026 06:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes NumberField keyboard editing for locales/formats whose Intl.NumberFormat output contains multi-character symbols (e.g. R$, km/h, localized scientific notation), by deriving allowed non-numeric input characters from formatToParts() and treating Unicode format/bidi control characters as ignorable during validation.

Changes:

  • Added a shared getFormatParts() helper and refactored locale detail derivation to use it.
  • Updated allowed-character derivation to include per-character symbols from Intl.NumberFormat.formatToParts() (excluding compact), enabling multi-character currency/unit/exponent decorations.
  • Updated input validation and parsing to tolerate Unicode format/bidi controls (\p{Cf}), and added regression tests for affected formats/locales.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
packages/react/src/number-field/utils/parse.ts Adds \p{Cf} handling and introduces getFormatParts() to unify formatToParts() enumeration.
packages/react/src/number-field/root/NumberFieldRoot.tsx Reworks getAllowedNonNumericKeys() to derive allowed characters from formatToParts() per character.
packages/react/src/number-field/input/NumberFieldInput.tsx Allows \p{Cf} characters through per-character validation (since parsing strips them).
packages/react/src/number-field/root/NumberFieldRoot.test.tsx Adds regression tests for multi-character currency/unit/exponent symbols and RTL scientific notation cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

atomiks added 3 commits June 29, 2026 16:30
The fa-IR scientific assertion relied on ICU emitting a U+200E control
character, which varies by engine/ICU version. Inject a known U+200E into
an otherwise-valid value instead so the test exercises the control-char
path deterministically.
@atomiks
atomiks merged commit 0a5c4f6 into mui:master Jun 29, 2026
6 checks passed
@atomiks
atomiks deleted the claude/inspiring-torvalds-5b2d1f branch June 29, 2026 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: number field Changes related to the number field component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[number field] Multi-character currency symbols are not editable (e.g. BRL R$)

2 participants