Skip to content

Commit eba273f

Browse files
authored
fix(PinInput): allow populating inputs by password manager's autofill (#2218)
1 parent 074becb commit eba273f

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

packages/core/src/PinInput/PinInput.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import userEvent from '@testing-library/user-event'
33
import { mount } from '@vue/test-utils'
44
import { beforeEach, describe, expect, it } from 'vitest'
55
import { axe } from 'vitest-axe'
6+
import { nextTick } from 'vue'
67
import PinInput from './story/_PinInput.vue'
78

89
describe('given default PinInput', () => {
@@ -271,4 +272,21 @@ describe('give PinInput type=number', async () => {
271272
expect(wrapper.emitted('complete')?.[0]?.[0]).toStrictEqual([0, 0, 0, 0, 0])
272273
})
273274
})
275+
276+
describe('autofill', () => {
277+
it('should populate the opt code in each box', async () => {
278+
/**
279+
* https://github.com/unovue/reka-ui/issues/2210
280+
* Password managers (like 1Password, Bitwarden, etc.) fill PIN inputs with `input` events
281+
*/
282+
for (const input of inputs) {
283+
input.setValue('0')
284+
input.trigger('input', { data: undefined })
285+
}
286+
await nextTick()
287+
288+
expect(inputs.map(i => i.element.value)).toStrictEqual(['0', '0', '0', '0', '0'])
289+
expect(wrapper.emitted('complete')?.[0]?.[0]).toStrictEqual([0, 0, 0, 0, 0])
290+
})
291+
})
274292
})

packages/core/src/PinInput/PinInputInput.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function handleInput(event: InputEvent) {
4242
return
4343
}
4444
45-
target.value = event.data ?? ''
45+
target.value = event.data || target.value.slice(-1)
4646
updateModelValueAt(props.index, target.value)
4747
4848
const nextEl = inputElements.value[props.index + 1]

packages/core/src/PinInput/PinInputRoot.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ const dir = useDirection(propDir)
9292
9393
const modelValue = useVModel(props, 'modelValue', emits, {
9494
defaultValue: props.defaultValue ?? [] as any,
95-
passive: (props.modelValue === undefined) as false,
95+
passive: true,
96+
deep: true,
9697
}) as Ref<PinInputValue<Type>>
9798
9899
const currentModelValue = computed(() => Array.isArray(modelValue.value) ? [...modelValue.value] : [])

0 commit comments

Comments
 (0)