Skip to content

Conversation

atomiks
Copy link
Contributor

@atomiks atomiks commented Sep 11, 2025

Handles a few more edge cases correctly.

Fixes #2735

@atomiks atomiks added the scope: number field Changes related to the number field. label Sep 11, 2025
Copy link

pkg-pr-new bot commented Sep 11, 2025

Open in StackBlitz

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

commit: 4e04a15

Copy link

netlify bot commented Sep 11, 2025

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 4e04a15
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/68c7e00ff744aa00094ab66f
😎 Deploy Preview https://deploy-preview-2725--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@mui-bot
Copy link

mui-bot commented Sep 11, 2025

Bundle size report

Bundle Parsed size Gzip size
@base-ui-components/react 🔺+2.07KB(+0.59%) 🔺+1.12KB(+1.02%)

Details of bundle changes

@atomiks atomiks force-pushed the fix/number-field-parsing branch from f60460e to 05d3dfb Compare September 11, 2025 08:50
@atomiks atomiks force-pushed the fix/number-field-parsing branch from 05d3dfb to c535a1c Compare September 11, 2025 08:53
: '6',
: '7',
: '8',
: '9',
Copy link
Member

@mj12albert mj12albert Sep 11, 2025

Choose a reason for hiding this comment

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

Suggested change
: '9',
: '9',
: '10',

@atomiks This is supposed to simply convert single digits?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should - let me know if that char is necessary though to handle another use case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

LLM review as this is out of my depth a bit:

We intentionally only normalize single-glyph Han digits (零/〇…九). Adding 十: '10' would break inputs like 三十 (30), which would become "310" under per-char substitution. If we need full ideographic number parsing, that should be a separate parser; this function is just digit normalization across scripts.

Copy link
Member

Choose a reason for hiding this comment

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

OK it doesn't matter then if it's just converting each individual char into a digit

Though in practice this would only work for 0-9 (and not 10+) since there are characters for 10/100/1000, so the numbering system is similar to roman numerals

But this is indeed an incredibly exotic use-case so it's ok

Copy link
Member

@michaldudak michaldudak left a comment

Choose a reason for hiding this comment

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

I found one more bug on master - when using a locale with "." as a thousand separator and "," as a decimal point, I can't type in more than one "." (and I can type more commas)

});

it('collapses extra dots from mixed-locale inputs', () => {
// First '.' is decimal; subsequent '.' are removed
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// First '.' is decimal; subsequent '.' are removed
// Last '.' is decimal; previous '.' are removed

Copy link
Contributor Author

@atomiks atomiks Sep 11, 2025

Choose a reason for hiding this comment

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

This could be the culprit in onKeyDown as it doesn't pass the locale, although it uses your runtime locale. Is it in US/English for you when the bug occurs?

const { decimal, currency, percentSign } = getNumberLocaleDetails(
  [],
  formatOptionsRef.current,
);

Copy link
Member

Choose a reason for hiding this comment

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

Yup, but I see you fixed it. Seems to work OK, but I found another issue 😅 - when on "pl-PL' locale (where we use spaces as thousand separators), I can't type in space at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@michaldudak I see, fixed

@atomiks atomiks force-pushed the fix/number-field-parsing branch from 7c72b98 to 43d3913 Compare September 11, 2025 20:32
Copy link
Member

@michaldudak michaldudak left a comment

Choose a reason for hiding this comment

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

Nice, I haven't found any more issues.

@atomiks atomiks force-pushed the fix/number-field-parsing branch from 0010ea2 to 632c655 Compare September 15, 2025 09:39
@atomiks atomiks merged commit 3dbc0e3 into mui:master Sep 15, 2025
20 checks passed
@atomiks atomiks deleted the fix/number-field-parsing branch September 15, 2025 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: number field Changes related to the number field.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[number field] onValueChange not triggered on input blur (focusout) since v1.0.0-beta.1
4 participants