Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/new-ducks-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"leva": patch
---

fix: removes suffix/prefix from numerical outputs - only keeping it as presentation in the input
Comment on lines +1 to +5
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify the "prefix" claim in the changeset description.

The changeset mentions removing both "suffix/prefix" from numerical outputs, but the code changes in number-plugin.ts only show suffix handling. Please confirm whether prefix has the same issue and is being fixed, or update the changeset description to reflect only suffix changes.


🏁 Script executed:

#!/bin/bash
# Search for prefix-related functionality in the codebase
rg -n -C3 'prefix' packages/leva/src/components/Number/ packages/leva/src/plugins/Number/ packages/leva/stories/inputs/Number.stories.tsx

Length of output: 73


🏁 Script executed:

#!/bin/bash
# Find Number-related files in the codebase
fd -t f 'number' packages/leva/src/ -i | head -20

Length of output: 203


🏁 Script executed:

#!/bin/bash
# Also search for any file containing "plugin" in the Number context
fd -t f 'plugin' packages/leva/src/ -i | grep -i number

Length of output: 52


🏁 Script executed:

#!/bin/bash
# Search for prefix usage across the entire packages/leva/src directory
rg -n 'prefix' packages/leva/src/ -C2

Length of output: 962


🏁 Script executed:

#!/bin/bash
# Search for suffix in Number component files
rg -n 'suffix' packages/leva/src/components/Number/ -C3

Length of output: 3510


🏁 Script executed:

#!/bin/bash
# Get the full content of number-plugin.ts to see what was changed
cat packages/leva/src/components/Number/number-plugin.ts

Length of output: 2211


🏁 Script executed:

#!/bin/bash
# Also check Number.tsx for suffix/prefix handling
cat packages/leva/src/components/Number/Number.tsx

Length of output: 2444


Update the changeset description to accurately reflect only suffix changes.

Verification confirms the code changes only handle suffix removal. The NumberSettings type defines only suffix?: string (no prefix property), and the normalize and format functions in number-plugin.ts only extract and apply suffix, not prefix. The changeset description claiming "suffix/prefix" removal is inaccurate—remove the prefix reference to match the actual implementation.

🤖 Prompt for AI Agents
.changeset/new-ducks-learn.md lines 1-5: the changeset description incorrectly
mentions removing "suffix/prefix" while the code only handles suffix; update the
markdown to remove the "prefix" reference so it accurately states that only
suffixes are removed (e.g., change "suffix/prefix" to "suffix" or reword to
"removes suffix from numerical outputs"). Ensure the changeset message matches
NumberSettings and the number-plugin.ts behavior.

7 changes: 3 additions & 4 deletions packages/leva/src/components/Number/number-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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 },
}
}
Expand Down
40 changes: 38 additions & 2 deletions packages/leva/stories/inputs/Number.stories.tsx
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -18,7 +18,7 @@ const Template: StoryFn = (args) => {

return (
<div>
<pre>{JSON.stringify(values, null, ' ')}</pre>
<pre data-testid="output">{JSON.stringify(values, null, ' ')}</pre>
</div>
)
}
Expand Down Expand Up @@ -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"')
}