diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index dcdac6a974..80187f6d34 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -3392,6 +3392,9 @@ state or inert ancestry; ordinary visible enabled controls retain their order. focus shared by the first-run launcher and Provider Settings. Each caller activates it while open and deactivates it on dismissal; destruction releases keyboard ownership without moving focus. Reopening captures the current opener. +Tab from a control outside the surface moves into it unless the caller passes +`claimOutsideFocus: false`, as the first-run launcher does; focus on the page +body still moves in. The launcher retains its hit-test/exclusive-surface arbitration and dismissal preferences. Provider Settings retains its existing visibility and save policy. Initial focus, transitions and DOM content remain with each screen. This @@ -4126,7 +4129,10 @@ which embeds the MAP_KEY. > a mission. Only **Enter God mode** runs it; Back is inert while it is loading. > Step changes focus the main action, announce the new heading separately from > mission progress, and refresh the scrolling affordance after the transition. Repeated Enter keys, -> double-clicks and activation during a step transition cannot launch a mission. +> double-clicks and activation during a step transition cannot launch a mission; a quick second +> click on Next still moves to the next step. Tab cycles inside the card, and moves into it from +> the page only when focus has nowhere else to be: Tab from the search bar or another control +> follows the page's order. > No layer and no optional API call happens until the final action is clicked. > The Stories announcement waits, from startup until onboarding closes, without > marking it seen. diff --git a/src/firstRunExperience.js b/src/firstRunExperience.js index 8772e9373f..3dbc02a6d0 100644 --- a/src/firstRunExperience.js +++ b/src/firstRunExperience.js @@ -513,6 +513,9 @@ export function initFirstRunExperience({ isActive: () => !closing && isTopmost(), onEscape: () => dismiss(), fallbackFocus: () => documentRef.body, + // The card sits beside a usable map: Tab from the search bar or any + // other control follows the page's order instead of jumping back in. + claimOutsideFocus: false, }); store.connect({ diff --git a/src/firstRunLauncherView.test.mjs b/src/firstRunLauncherView.test.mjs index a8041fd35d..204584a577 100644 --- a/src/firstRunLauncherView.test.mjs +++ b/src/firstRunLauncherView.test.mjs @@ -152,6 +152,37 @@ test('the card is hidden until initialized, then revealed with its copy', async ); }); +test('a quick second click on NEXT moves on, and never launches', async (t) => { + let calls = 0; + const { root, frames } = await launch(t, { + dataManager: { + setEnabled: async () => { + calls++; + return true; + }, + }, + }); + const primary = root.querySelector('[data-first-run-primary]'); + const press = (detail) => { + primary.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true })); + primary.dispatchEvent(new MouseEvent('click', { bubbles: true, detail })); + }; + press(1); + await settle(frames); + assert.ok(root.querySelector('[data-first-run-start]'), 'on the second step'); + // The second click of a double click, after the step settled, moves on. + press(2); + await settle(frames); + assert.equal(primary.dataset.firstRunChoice, 'explore', 'on the last step'); + press(2); + await settle(frames); + assert.equal(calls, 0); + assert.equal(root.dataset.state ?? null, null, 'a double click never starts'); + press(1); + await settle(frames); + assert.ok(root.dataset.state, 'a single click starts'); +}); + test('a busy mission marks the choices aria-disabled, never disabled', async (t) => { let finish; let calls = 0; diff --git a/src/ui/surfaceKeyboard.js b/src/ui/surfaceKeyboard.js index 887ae1eb31..e3b5a2c843 100644 --- a/src/ui/surfaceKeyboard.js +++ b/src/ui/surfaceKeyboard.js @@ -9,6 +9,10 @@ * @param {() => boolean} options.isActive Whether this surface may handle input now. * @param {() => void} options.onEscape Caller-owned dismissal action. * @param {() => HTMLElement} [options.fallbackFocus] Return target if the opener is gone. + * @param {boolean} [options.claimOutsideFocus=true] Tab from a control outside + * the surface moves into it. False leaves Tab to the page then, for a + * surface that does not hold the keyboard (focus that has nowhere to be, + * on the page body, still moves in). * @returns {{activate: Function, deactivate: Function, destroy: Function}} */ export function createSurfaceKeyboard({ @@ -17,6 +21,7 @@ export function createSurfaceKeyboard({ isActive, onEscape, fallbackFocus, + claimOutsideFocus = true, }) { let active = false; let destroyed = false; @@ -54,6 +59,11 @@ export function createSurfaceKeyboard({ // Allow native scrolling when cycling to an off-screen control in a short // surface. Initial focus and return focus use the caller's separate policy. if (!root.contains(focused)) { + const lost = + !focused || + focused === documentRef.body || + focused === documentRef.documentElement; + if (!claimOutsideFocus && !lost) return; event.preventDefault(); (event.shiftKey ? last : first).focus(); } else if (event.shiftKey && focused === first) { diff --git a/src/ui/surfaceKeyboard.test.mjs b/src/ui/surfaceKeyboard.test.mjs index d9b8388cf1..51a6b8238a 100644 --- a/src/ui/surfaceKeyboard.test.mjs +++ b/src/ui/surfaceKeyboard.test.mjs @@ -2,7 +2,7 @@ import test from 'node:test'; import assert from 'node:assert/strict'; import { createSurfaceKeyboard } from './surfaceKeyboard.js'; -function fixture() { +function fixture({ claimOutsideFocus } = {}) { const listeners = new Set(); const documentRef = { activeElement: null, @@ -54,6 +54,7 @@ function fixture() { isActive: () => visible, onEscape: () => onEscape(), fallbackFocus: () => fallback, + claimOutsideFocus, }); opener.focus(); const event = (key, extra = {}) => ({ @@ -134,6 +135,23 @@ test('Tab enters from outside in either direction and wraps only at an edge', () ); }); +test('a surface that does not claim outside focus leaves Tab to the page', () => { + const f = fixture({ claimOutsideFocus: false }); + f.controller.activate(); + // From a control outside (the search bar), Tab follows the page. + f.opener.focus(); + assert.equal(f.send('Tab').defaultPrevented, false); + assert.equal(f.send('Tab', { shiftKey: true }).defaultPrevented, false); + assert.equal(f.documentRef.activeElement, f.opener); + // Focus with nowhere to be still moves in, and wraps inside as before. + f.documentRef.activeElement = null; + assert.equal(f.send('Tab').defaultPrevented, true); + assert.equal(f.documentRef.activeElement, f.first); + f.last.focus(); + f.send('Tab'); + assert.equal(f.documentRef.activeElement, f.first); +}); + test('Tab uses current controls and skips hidden/disabled nodes without changing native middle movement', () => { const f = fixture(); f.controller.activate(); diff --git a/src/ui/views/WelcomeView.vue b/src/ui/views/WelcomeView.vue index 5bcf1d00b3..395facfb4e 100644 --- a/src/ui/views/WelcomeView.vue +++ b/src/ui/views/WelcomeView.vue @@ -41,13 +41,16 @@ let pressedOn = null; function onPrimaryDown() { pressedOn = settling.value ? null : step.value; } +// A quick second click still moves to the next step, so the button never +// looks dead; only the launch itself takes a single click, so a double click +// that began on NEXT never confirms the start it lands on. function onPrimary(event) { - if (settling.value || event.detail > 1) return; + if (settling.value) return; const pressed = pressedOn; pressedOn = null; - if (event.detail === 1 && pressed !== step.value) return; - if (step.value < STEPS) go(step.value + 1, event); - else controls.value?.choose(start.value); + if (event.detail >= 1 && pressed !== step.value) return; + if (step.value < STEPS) go(step.value + 1); + else if (event.detail <= 1) controls.value?.choose(start.value); } // GEV Stories opens in place: the card closes as Skip would, then Explore // takes the globe. The Stories announcement stays hidden while Stories loads,