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, '  ')}
) } @@ -89,3 +89,39 @@ Complete.play = async ({ canvasElement }) => { // Verify the story renders await expect(canvas.getByText(/5/)).toBeInTheDocument() } + +export const SuffixValueTest = Template.bind({}) +SuffixValueTest.args = { + value: 10, + min: 10, + suffix: 'ms', +} +SuffixValueTest.play = async ({ canvasElement }) => { + const canvas = within(canvasElement) + + // Verify initial value is a number, not a string with suffix + const output = canvas.getByTestId('output') + await expect(output.textContent).toContain('"foo": 10') + + // Find the input field (Leva panel is rendered in document.body) + const input = within(document.body).getByLabelText(/foo/i) as HTMLInputElement + + // Verify the input displays the suffix + await expect(input.value).toBe('10ms') + + // Change the value + await userEvent.clear(input) + await userEvent.type(input, '15') + + // Blur to trigger update + await userEvent.tab() + + // Wait a bit for the state to update + await new Promise((resolve) => setTimeout(resolve, 100)) + + // Verify the returned value is numeric without suffix + await expect(output.textContent).toContain('"foo": 15') + + // Verify it doesn't contain the suffix in the value + await expect(output.textContent).not.toContain('"foo": "15ms"') +} From d783ea5a119a65fa886d22aa3806274f36d75e66 Mon Sep 17 00:00:00 2001 From: Gianmarco Date: Fri, 31 Oct 2025 19:10:22 +0100 Subject: [PATCH 3/3] Fix numerical output by removing suffix/prefix --- .changeset/new-ducks-learn.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/new-ducks-learn.md 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