diff --git a/packages/hub-ui/src/client/components/display/OtpInput.vue b/packages/hub-ui/src/client/components/display/OtpInput.vue index 3102602d..695807fc 100644 --- a/packages/hub-ui/src/client/components/display/OtpInput.vue +++ b/packages/hub-ui/src/client/components/display/OtpInput.vue @@ -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) + }) }, }) diff --git a/tests/e2e/floating-dock.spec.ts b/tests/e2e/floating-dock.spec.ts index 4da6a9a7..8639981b 100644 --- a/tests/e2e/floating-dock.spec.ts +++ b/tests/e2e/floating-dock.spec.ts @@ -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()