Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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/plenty-spies-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"leva": patch
---

fix: update string input value in real-time
7 changes: 6 additions & 1 deletion packages/leva/src/components/ValueInput/ValueInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type ValueInputProps = {
onChange: (value: string) => void
onKeyDown?: (event: React.KeyboardEvent) => void
rows?: number
liveUpdate?: boolean
}

export function ValueInput({
Expand All @@ -25,6 +26,7 @@ export function ValueInput({
id,
inputType = 'text',
rows = 0,
liveUpdate = false,
...props
}: ValueInputProps) {
const { id: _id, emitOnEditStart, emitOnEditEnd, disabled } = useInputContext()
Expand Down Expand Up @@ -84,7 +86,10 @@ export function ValueInput({
autoComplete="off"
spellCheck="false"
value={value}
onChange={update(onChange)}
onChange={update((value) => {
onChange(value)
if (type !== "number" || liveUpdate) onUpdate(value)
})}
onFocus={() => emitOnEditStart()}
onKeyPress={onKeyPress}
onKeyDown={onKeyDown}
Expand Down
2 changes: 1 addition & 1 deletion packages/leva/src/plugins/String/String.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const NonEditableString = styled('div', {
})

export function String({ displayValue, onUpdate, onChange, editable = true, ...props }: BaseStringProps) {
if (editable) return <ValueInput value={displayValue} onUpdate={onUpdate} onChange={onChange} {...props} />
if (editable) return <ValueInput value={displayValue} onUpdate={onUpdate} onChange={onChange} liveUpdate {...props} />
return <NonEditableString>{displayValue}</NonEditableString>
}

Expand Down