Skip to content

Commit a1b9584

Browse files
committed
fix: pin input autofill
1 parent 0f9c921 commit a1b9584

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

.changeset/bumpy-teams-battle.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@zag-js/pin-input": patch
3+
---
4+
5+
Fix issue where OTP SMS autofill doesn't work as expected.

.xstate/pin-input.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,15 @@ const fetchMachine = createMachine({
238238
},
239239
setFocusedValue({
240240
context,
241-
event
241+
event,
242+
flush
242243
}) {
243244
const focusedValue = computed("focusedValue");
244245
const focusedIndex = context.get("focusedIndex");
245246
const value = getNextValue(focusedValue, event.value);
246-
context.set("value", setValueAtIndex(computed("_value"), focusedIndex, value));
247+
flush(() => {
248+
context.set("value", setValueAtIndex(computed("_value"), focusedIndex, value));
249+
});
247250
},
248251
revertInputValue({
249252
context,

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,13 @@ export const machine = createMachine({
196196
const value = fill(event.value, context.get("count"))
197197
context.set("value", value)
198198
},
199-
setFocusedValue({ context, event, computed }) {
199+
setFocusedValue({ context, event, computed, flush }) {
200200
const focusedValue = computed("focusedValue")
201201
const focusedIndex = context.get("focusedIndex")
202202
const value = getNextValue(focusedValue, event.value)
203-
context.set("value", setValueAtIndex(computed("_value"), focusedIndex, value))
203+
flush(() => {
204+
context.set("value", setValueAtIndex(computed("_value"), focusedIndex, value))
205+
})
204206
},
205207
revertInputValue({ context, computed, scope }) {
206208
const inputEl = dom.getInputElAtIndex(scope, context.get("focusedIndex"))

0 commit comments

Comments
 (0)