@baukit/a11y-core 0.19.2 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/route-focus.d.ts +0 -2
- package/dist/route-focus.d.ts.map +1 -1
- package/dist/route-focus.js +4 -22
- package/dist/route-focus.js.map +1 -1
- package/package.json +1 -1
- package/src/route-focus.test.ts +13 -4
- package/src/route-focus.ts +3 -22
package/dist/route-focus.d.ts
CHANGED
|
@@ -5,8 +5,6 @@ export interface RouteFocusRuntime {
|
|
|
5
5
|
document: Document;
|
|
6
6
|
requestAnimationFrame(callback: FrameRequestCallback): number;
|
|
7
7
|
cancelAnimationFrame(handle: number): void;
|
|
8
|
-
setTimeout(callback: () => void, delayMs: number): number;
|
|
9
|
-
clearTimeout(handle: number): void;
|
|
10
8
|
now(): number;
|
|
11
9
|
}
|
|
12
10
|
export interface RouteFocusControllerOptions {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-focus.d.ts","sourceRoot":"","sources":["../src/route-focus.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG;IACvC,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;CACrC,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,QAAQ,CAAC;IACnB,qBAAqB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,MAAM,CAAC;IAC9D,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,
|
|
1
|
+
{"version":3,"file":"route-focus.d.ts","sourceRoot":"","sources":["../src/route-focus.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG;IACvC,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;CACrC,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,QAAQ,CAAC;IACnB,qBAAqB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,MAAM,CAAC;IAC9D,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,GAAG,IAAI,MAAM,CAAC;CACf;AAED,MAAM,WAAW,2BAA2B;IAC1C,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,MAAM,EAAE,MAAM,gBAAgB,GAAG,IAAI,GAAG,MAAM,IAAI,CAAC;IAC9D,OAAO,IAAI,IAAI,CAAC;CACjB;AA+FD,4EAA4E;AAC5E,wBAAgB,0BAA0B,CACxC,OAAO,GAAE,iBAAoC,EAC7C,OAAO,GAAE,2BAAgC,GACxC,oBAAoB,CAmDtB"}
|
package/dist/route-focus.js
CHANGED
|
@@ -7,10 +7,6 @@ function browserRuntime() {
|
|
|
7
7
|
cancelAnimationFrame: (handle) => {
|
|
8
8
|
globalThis.cancelAnimationFrame(handle);
|
|
9
9
|
},
|
|
10
|
-
setTimeout: (callback, delayMs) => globalThis.setTimeout(callback, delayMs),
|
|
11
|
-
clearTimeout: (handle) => {
|
|
12
|
-
globalThis.clearTimeout(handle);
|
|
13
|
-
},
|
|
14
10
|
now: () => Date.now(),
|
|
15
11
|
};
|
|
16
12
|
}
|
|
@@ -51,41 +47,27 @@ function attemptFocus(document, target, allowed) {
|
|
|
51
47
|
const focused = activeTarget(document);
|
|
52
48
|
return focused === target || focusMovedElsewhere(document, focused, allowed) ? 'done' : 'retry';
|
|
53
49
|
}
|
|
50
|
+
/** Checks the deadline after each attempt, so a renderer stall past the timeout still gets one. */
|
|
54
51
|
function retryFocus(scope, getTarget, allowedActiveTargets, observedTargets) {
|
|
55
52
|
const { runtime, timeoutMs } = scope;
|
|
56
53
|
const startedAt = runtime.now();
|
|
57
54
|
let frame = null;
|
|
58
|
-
let timer = null;
|
|
59
|
-
let stopped = false;
|
|
60
55
|
const stop = () => {
|
|
61
|
-
if (stopped)
|
|
62
|
-
return;
|
|
63
|
-
stopped = true;
|
|
64
56
|
if (frame !== null)
|
|
65
57
|
runtime.cancelAnimationFrame(frame);
|
|
66
|
-
if (timer !== null)
|
|
67
|
-
runtime.clearTimeout(timer);
|
|
68
58
|
frame = null;
|
|
69
|
-
timer = null;
|
|
70
59
|
};
|
|
71
60
|
const attempt = () => {
|
|
72
61
|
frame = null;
|
|
73
|
-
if (stopped)
|
|
74
|
-
return;
|
|
75
|
-
if (runtime.now() - startedAt >= timeoutMs) {
|
|
76
|
-
stop();
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
62
|
const target = getTarget();
|
|
80
63
|
if (target !== null)
|
|
81
64
|
observedTargets?.add(target);
|
|
82
|
-
if (attemptFocus(runtime.document, target, allowedActiveTargets) === 'done')
|
|
83
|
-
|
|
65
|
+
if (attemptFocus(runtime.document, target, allowedActiveTargets) === 'done')
|
|
66
|
+
return;
|
|
67
|
+
if (runtime.now() - startedAt >= timeoutMs)
|
|
84
68
|
return;
|
|
85
|
-
}
|
|
86
69
|
frame = runtime.requestAnimationFrame(attempt);
|
|
87
70
|
};
|
|
88
|
-
timer = runtime.setTimeout(stop, timeoutMs);
|
|
89
71
|
frame = runtime.requestAnimationFrame(attempt);
|
|
90
72
|
return stop;
|
|
91
73
|
}
|
package/dist/route-focus.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-focus.js","sourceRoot":"","sources":["../src/route-focus.ts"],"names":[],"mappings":"AAAA,MAAM,8BAA8B,GAAG,IAAI,CAAC;AAC5C,MAAM,oBAAoB,GAAG,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"route-focus.js","sourceRoot":"","sources":["../src/route-focus.ts"],"names":[],"mappings":"AAAA,MAAM,8BAA8B,GAAG,IAAI,CAAC;AAC5C,MAAM,oBAAoB,GAAG,yCAAyC,CAAC;AAsBvE,SAAS,cAAc;IACrB,OAAO;QACL,QAAQ,EAAE,UAAU,CAAC,QAA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,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baukit/a11y-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "Accessibility behavior shared by web and React Native products: overlay focus, inert background content, announcements, reduced motion, and keyboard movement.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Patrick Koss",
|
package/src/route-focus.test.ts
CHANGED
|
@@ -22,10 +22,6 @@ function runtime(): RouteFocusRuntime {
|
|
|
22
22
|
cancelAnimationFrame: (handle) => {
|
|
23
23
|
window.clearTimeout(handle);
|
|
24
24
|
},
|
|
25
|
-
setTimeout: (callback, delayMs) => window.setTimeout(callback, delayMs),
|
|
26
|
-
clearTimeout: (handle) => {
|
|
27
|
-
window.clearTimeout(handle);
|
|
28
|
-
},
|
|
29
25
|
now: () => Date.now(),
|
|
30
26
|
};
|
|
31
27
|
}
|
|
@@ -121,6 +117,19 @@ describe('createRouteFocusController', () => {
|
|
|
121
117
|
expect(vi.getTimerCount()).toBe(0);
|
|
122
118
|
});
|
|
123
119
|
|
|
120
|
+
it('still focuses the target when the first frame arrives after the timeout', () => {
|
|
121
|
+
const instance = controller();
|
|
122
|
+
const trigger = focusable('button');
|
|
123
|
+
trigger.focus();
|
|
124
|
+
const heading = focusable('h1');
|
|
125
|
+
|
|
126
|
+
instance.enterRoute(() => heading);
|
|
127
|
+
vi.setSystemTime(RETRY_TIMEOUT_MS * 2);
|
|
128
|
+
vi.advanceTimersByTime(FRAME_MS);
|
|
129
|
+
|
|
130
|
+
expect(document.activeElement).toBe(heading);
|
|
131
|
+
});
|
|
132
|
+
|
|
124
133
|
it('does not steal focus when the user moves to another reachable control', () => {
|
|
125
134
|
const instance = controller();
|
|
126
135
|
const trigger = focusable('button');
|
package/src/route-focus.ts
CHANGED
|
@@ -9,8 +9,6 @@ export interface RouteFocusRuntime {
|
|
|
9
9
|
document: Document;
|
|
10
10
|
requestAnimationFrame(callback: FrameRequestCallback): number;
|
|
11
11
|
cancelAnimationFrame(handle: number): void;
|
|
12
|
-
setTimeout(callback: () => void, delayMs: number): number;
|
|
13
|
-
clearTimeout(handle: number): void;
|
|
14
12
|
now(): number;
|
|
15
13
|
}
|
|
16
14
|
|
|
@@ -30,10 +28,6 @@ function browserRuntime(): RouteFocusRuntime {
|
|
|
30
28
|
cancelAnimationFrame: (handle) => {
|
|
31
29
|
globalThis.cancelAnimationFrame(handle);
|
|
32
30
|
},
|
|
33
|
-
setTimeout: (callback, delayMs) => globalThis.setTimeout(callback, delayMs),
|
|
34
|
-
clearTimeout: (handle) => {
|
|
35
|
-
globalThis.clearTimeout(handle);
|
|
36
|
-
},
|
|
37
31
|
now: () => Date.now(),
|
|
38
32
|
};
|
|
39
33
|
}
|
|
@@ -91,6 +85,7 @@ function attemptFocus(
|
|
|
91
85
|
return focused === target || focusMovedElsewhere(document, focused, allowed) ? 'done' : 'retry';
|
|
92
86
|
}
|
|
93
87
|
|
|
88
|
+
/** Checks the deadline after each attempt, so a renderer stall past the timeout still gets one. */
|
|
94
89
|
function retryFocus(
|
|
95
90
|
scope: FocusScope,
|
|
96
91
|
getTarget: () => RouteFocusTarget | null,
|
|
@@ -100,35 +95,21 @@ function retryFocus(
|
|
|
100
95
|
const { runtime, timeoutMs } = scope;
|
|
101
96
|
const startedAt = runtime.now();
|
|
102
97
|
let frame: number | null = null;
|
|
103
|
-
let timer: number | null = null;
|
|
104
|
-
let stopped = false;
|
|
105
98
|
|
|
106
99
|
const stop = (): void => {
|
|
107
|
-
if (stopped) return;
|
|
108
|
-
stopped = true;
|
|
109
100
|
if (frame !== null) runtime.cancelAnimationFrame(frame);
|
|
110
|
-
if (timer !== null) runtime.clearTimeout(timer);
|
|
111
101
|
frame = null;
|
|
112
|
-
timer = null;
|
|
113
102
|
};
|
|
114
103
|
|
|
115
104
|
const attempt = (): void => {
|
|
116
105
|
frame = null;
|
|
117
|
-
if (stopped) return;
|
|
118
|
-
if (runtime.now() - startedAt >= timeoutMs) {
|
|
119
|
-
stop();
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
106
|
const target = getTarget();
|
|
123
107
|
if (target !== null) observedTargets?.add(target);
|
|
124
|
-
if (attemptFocus(runtime.document, target, allowedActiveTargets) === 'done')
|
|
125
|
-
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
108
|
+
if (attemptFocus(runtime.document, target, allowedActiveTargets) === 'done') return;
|
|
109
|
+
if (runtime.now() - startedAt >= timeoutMs) return;
|
|
128
110
|
frame = runtime.requestAnimationFrame(attempt);
|
|
129
111
|
};
|
|
130
112
|
|
|
131
|
-
timer = runtime.setTimeout(stop, timeoutMs);
|
|
132
113
|
frame = runtime.requestAnimationFrame(attempt);
|
|
133
114
|
return stop;
|
|
134
115
|
}
|