mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 17:52:21 +00:00
Let a quick second click on Next move on, and Tab leave the welcome for the page
The second click of a double click on NEXT was dropped, so the button looked dead; it now moves to the next step, and only the launch itself still takes a single click. Tab from the search bar or another control jumped back into the card; the card no longer claims focus from the page, and still takes it when focus has nowhere else to be. Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
1 parent
4d42c56bdf
commit
866eadbe5e
6 files changed
+77
-6
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user