diff --git a/.changeset/new-ducks-learn.md b/.changeset/new-ducks-learn.md new file mode 100644 index 00000000..13ee4704 --- /dev/null +++ b/.changeset/new-ducks-learn.md @@ -0,0 +1,5 @@ +--- +"leva": patch +--- + +fix: removes suffix/prefix from numerical outputs - only keeping it as presentation in the input diff --git a/packages/leva/src/components/Number/number-plugin.ts b/packages/leva/src/components/Number/number-plugin.ts index a97cdabc..be0332d0 100644 --- a/packages/leva/src/components/Number/number-plugin.ts +++ b/packages/leva/src/components/Number/number-plugin.ts @@ -13,11 +13,10 @@ export const schema = (v: any) => { return false } -export const sanitize = (v: any, { min = -Infinity, max = Infinity, suffix }: InternalNumberSettings) => { +export const sanitize = (v: any, { min = -Infinity, max = Infinity }: InternalNumberSettings) => { const _v = parseFloat(v as string) if (v === '' || isNaN(_v)) throw Error('Invalid number') - const f = clamp(_v, min, max) - return suffix ? f + suffix : f + return clamp(_v, min, max) } export const format = (v: any, { pad = 0, suffix }: InternalNumberSettings) => { @@ -50,7 +49,7 @@ export const normalize = ({ value, ...settings }: NumberInput) => { const pad = Math.round(clamp(Math.log10(1 / padStep), 0, 2)) return { - value: suffix ? _value + suffix : _value, + value: _value, settings: { initialValue: _value, step, pad, min, max, suffix, ..._settings }, } } diff --git a/packages/leva/stories/inputs/Number.stories.tsx b/packages/leva/stories/inputs/Number.stories.tsx index 165afc38..8d813c07 100644 --- a/packages/leva/stories/inputs/Number.stories.tsx +++ b/packages/leva/stories/inputs/Number.stories.tsx @@ -1,6 +1,6 @@ import React from 'react' import { StoryFn, Meta } from '@storybook/react' -import { expect, within } from 'storybook/test' +import { expect, within, userEvent } from 'storybook/test' import Reset from '../components/decorator-reset' @@ -18,7 +18,7 @@ const Template: StoryFn = (args) => { return (
{JSON.stringify(values, null, ' ')}
+ {JSON.stringify(values, null, ' ')}