From 79c21b9e0f1033e35f69ef05a1a8d1103bd6f884 Mon Sep 17 00:00:00 2001 From: jer3m01 Date: Tue, 30 Jul 2024 23:00:47 +0200 Subject: [PATCH] fix(number-field): only format when enabled --- biome.json | 2 +- packages/core/src/number-field/number-field-root.tsx | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/biome.json b/biome.json index 7233a3e9f..2c60fb597 100644 --- a/biome.json +++ b/biome.json @@ -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, diff --git a/packages/core/src/number-field/number-field-root.tsx b/packages/core/src/number-field/number-field-root.tsx index de3b68b07..9421aa133 100644 --- a/packages/core/src/number-field/number-field-root.tsx +++ b/packages/core/src/number-field/number-field-root.tsx @@ -183,6 +183,8 @@ export function NumberFieldRoot( 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 ?? "") @@ -202,7 +204,7 @@ export function NumberFieldRoot( 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)); }, @@ -265,7 +267,7 @@ export function NumberFieldRoot( 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();