From a581a9a68880aaef8e9f9fee87e89cd8516f25d4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 31 Oct 2025 17:41:15 +0000 Subject: [PATCH 1/3] Initial plan From e5691138cccd74f17a77918f08dd2389bf9f9771 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 31 Oct 2025 17:54:40 +0000 Subject: [PATCH 2/3] Fix suffix being added to numerical input values and add test Co-authored-by: gsimone <1862172+gsimone@users.noreply.github.com> --- .../src/components/Number/number-plugin.ts | 7 ++-- .../leva/stories/inputs/Number.stories.tsx | 40 ++++++++++++++++++- 2 files changed, 41 insertions(+), 6 deletions(-) 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, ' ')}