Skip to content

Commit da88564

Browse files
authored
fix: handle numeric number input set value (#3170)
1 parent b447533 commit da88564

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@zag-js/number-input": patch
3+
---
4+
5+
Fix issue where calling `api.setValue` with a number throws when `formatOptions` is defined.

packages/machines/number-input/src/number-input.machine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ export const machine = createMachine({
382382
context.set("value", formatValue(nextValue, { computed, prop }))
383383
},
384384
setRawValue({ context, event, prop, computed }) {
385-
let nextValue = parseValue(event.value, { computed, prop })
385+
let nextValue = typeof event.value === "number" ? event.value : parseValue(event.value, { computed, prop })
386386
if (!prop("allowOverflow")) nextValue = clampValue(nextValue, prop("min"), prop("max"))
387387
context.set("value", formatValue(nextValue, { computed, prop }))
388388
},

0 commit comments

Comments
 (0)