Skip to content

Commit

Permalink
fix(number-field): only format when enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
jer3m01 committed Jul 30, 2024
1 parent 7ceb249 commit 79c21b9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"files": {
"ignore": ["./tsconfig.json", "*/netlify/*"]
"ignore": ["./tsconfig.json", "*/netlify/*", "**/package.json"]
},
"vcs": {
"enabled": true,
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/number-field/number-field-root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ export function NumberFieldRoot<T extends ValidComponent = "div">(
return new NumberFormatter(locale(), local.formatOptions);
});

const formatNumber = (number: number) => local.format ? numberFormatter().format(number) : number.toString();

const parseRawValue = (value: string | number | undefined) =>
local.format && typeof value !== "number"
? numberParser().parse(value ?? "")
Expand All @@ -202,7 +204,7 @@ export function NumberFieldRoot<T extends ValidComponent = "div">(
defaultValue: () => local.defaultValue ?? local.rawValue,
onChange: (value) => {
local.onChange?.(
typeof value === "number" ? numberFormatter().format(value) : value,
typeof value === "number" ? formatNumber(value) : value,
);
local.onRawValueChange?.(parseRawValue(value));
},
Expand Down Expand Up @@ -265,7 +267,7 @@ export function NumberFieldRoot<T extends ValidComponent = "div">(
setValue,
rawValue: () => parseRawValue(value()),
generateId: createGenerateId(() => access(formControlProps.id)!),
formatNumber: (number: number) => numberFormatter().format(number),
formatNumber,
format: () => {
if (!local.format) return;
let rawValue = context.rawValue();
Expand Down

0 comments on commit 79c21b9

Please sign in to comment.