Skip to content
Open
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
13 changes: 9 additions & 4 deletions packages/hub-ui/src/client/components/display/OtpInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,15 @@ function boxClass(i: number): string {
defineExpose({
/** Focus the first empty box (or the last one when full). */
focus() {
const firstEmpty = digits.value.findIndex(d => !d)
focusBox(firstEmpty === -1
? props.length - 1
: firstEmpty)
// Look up the target on the next tick: callers can change the model
// right before calling `focus()` (a failed attempt clears the code),
// and the new prop value only arrives on re-render.
nextTick(() => {
const firstEmpty = digits.value.findIndex(d => !d)
focusBox(firstEmpty === -1
? props.length - 1
: firstEmpty)
})
},
})
</script>
Expand Down
25 changes: 25 additions & 0 deletions tests/e2e/floating-dock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,31 @@ for (const trusted of [false, true]) {
})
}

// Only the untrusted dock mounts the OTP view.
if (!trusted) {
test('a rejected code clears the boxes and refocuses the first digit', async ({ page }) => {
const dock = page.locator('#devframes-dock')
await dock.hover()
const button = dock.getByRole('button', { name, exact: true })
// Wait for expansion so the click lands beneath the centered logo.
await expect(button).toBeInViewport()
const logo = dock.locator(':scope > div').first()
await expect(logo).toHaveCSS('opacity', '0')
const point = await center(button)
await page.mouse.click(point.x, point.y)
await expect(page.locator('body')).toHaveAttribute('data-selected', '~client-auth-notice')

const digit = (index: number) => page.getByRole('textbox', { name: `Digit ${index} of 6`, exact: true })
await digit(1).click()
await expect(digit(1)).toBeFocused()
await page.keyboard.type('000000')
await expect(page.getByText('That code didn\'t match.')).toBeVisible()
for (let i = 1; i <= 6; i++)
await expect(digit(i)).toHaveValue('')
await expect(digit(1)).toBeFocused()
})
}

test('minimized controls leave the accessibility tree and tab order', async ({ page }) => {
const dock = page.locator('#devframes-dock')
await dock.hover()
Expand Down
Loading