@y14e/roving-tabindex 3.1.19 → 3.1.21
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/README.md +3 -3
- package/dist/index.bundle.cjs +26 -23
- package/dist/index.bundle.js +26 -23
- package/dist/index.cjs +41 -17
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +20 -17
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -13,11 +13,11 @@ npm i @y14e/roving-tabindex
|
|
|
13
13
|
import { createRovingTabIndex } from '@y14e/roving-tabindex';
|
|
14
14
|
|
|
15
15
|
// CDNs
|
|
16
|
-
import { createRovingTabIndex } from 'https://esm.sh/@y14e/roving-tabindex@3.1.
|
|
16
|
+
import { createRovingTabIndex } from 'https://esm.sh/@y14e/roving-tabindex@3.1.21';
|
|
17
17
|
// or
|
|
18
|
-
import { createRovingTabIndex } from 'https://cdn.jsdelivr.net/npm/@y14e/roving-tabindex@3.1.
|
|
18
|
+
import { createRovingTabIndex } from 'https://cdn.jsdelivr.net/npm/@y14e/roving-tabindex@3.1.21/+esm';
|
|
19
19
|
// or
|
|
20
|
-
import { createRovingTabIndex } from 'https://esm.unpkg.com/@y14e/roving-tabindex@3.1.
|
|
20
|
+
import { createRovingTabIndex } from 'https://esm.unpkg.com/@y14e/roving-tabindex@3.1.21';
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## 📦 APIs
|
package/dist/index.bundle.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
// node_modules/@y14e/
|
|
3
|
+
// node_modules/@y14e/attribute-util/dist/index.js
|
|
4
4
|
var DEFAULT_PARSER = (value) => value.split(/\s+/);
|
|
5
5
|
var DEFAULT_SERIALIZER = (tokens) => tokens.join(" ");
|
|
6
|
-
function
|
|
7
|
-
const value = element.getAttribute(
|
|
6
|
+
function addAttributeToken(element, name, token, options = {}) {
|
|
7
|
+
const value = element.getAttribute(name)?.trim();
|
|
8
8
|
const {
|
|
9
9
|
caseInsensitive = false,
|
|
10
10
|
parse = DEFAULT_PARSER,
|
|
@@ -15,12 +15,12 @@ function addTokenToAttribute(element, attribute, token, options = {}) {
|
|
|
15
15
|
const lower = token.toLowerCase();
|
|
16
16
|
if (tokens.every((token2) => token2.toLowerCase() !== lower)) {
|
|
17
17
|
tokens.push(token);
|
|
18
|
-
element.setAttribute(
|
|
18
|
+
element.setAttribute(name, serialize(tokens));
|
|
19
19
|
}
|
|
20
20
|
} else {
|
|
21
21
|
const set = new Set(tokens);
|
|
22
22
|
set.add(token);
|
|
23
|
-
element.setAttribute(
|
|
23
|
+
element.setAttribute(name, serialize([...set]));
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
var snapshots = /* @__PURE__ */ new WeakMap();
|
|
@@ -30,22 +30,22 @@ function restoreAttributes(element_or_elements) {
|
|
|
30
30
|
if (!snapshot) {
|
|
31
31
|
continue;
|
|
32
32
|
}
|
|
33
|
-
for (const [
|
|
34
|
-
value === null ? element.removeAttribute(
|
|
33
|
+
for (const [name, value] of snapshot.entries()) {
|
|
34
|
+
value === null ? element.removeAttribute(name) : element.setAttribute(name, value);
|
|
35
35
|
}
|
|
36
36
|
snapshots.delete(element);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
function saveAttributes(element_or_elements,
|
|
40
|
-
const
|
|
39
|
+
function saveAttributes(element_or_elements, name_or_names) {
|
|
40
|
+
const names = Array.isArray(name_or_names) ? name_or_names : [name_or_names];
|
|
41
41
|
(Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]).forEach((element) => {
|
|
42
42
|
let snapshot = snapshots.get(element);
|
|
43
43
|
if (!snapshot) {
|
|
44
44
|
snapshot = /* @__PURE__ */ new Map();
|
|
45
45
|
snapshots.set(element, snapshot);
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
snapshot.set(
|
|
47
|
+
names.forEach((name) => {
|
|
48
|
+
snapshot.set(name, element.getAttribute(name));
|
|
49
49
|
});
|
|
50
50
|
});
|
|
51
51
|
}
|
|
@@ -366,17 +366,20 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
366
366
|
noStart = false;
|
|
367
367
|
}
|
|
368
368
|
if (selector !== "") {
|
|
369
|
+
let hasError = false;
|
|
369
370
|
if (typeof selector !== "string" || !selector.trim()) {
|
|
370
|
-
|
|
371
|
-
selector = "";
|
|
371
|
+
hasError = true;
|
|
372
372
|
} else {
|
|
373
373
|
try {
|
|
374
|
-
container.querySelector(selector);
|
|
374
|
+
this.#container.querySelector(selector);
|
|
375
375
|
} catch {
|
|
376
|
-
|
|
377
|
-
selector = "";
|
|
376
|
+
hasError = true;
|
|
378
377
|
}
|
|
379
378
|
}
|
|
379
|
+
if (hasError) {
|
|
380
|
+
console.warn("Invalid selector. Fallback: no selector string.");
|
|
381
|
+
selector = "";
|
|
382
|
+
}
|
|
380
383
|
}
|
|
381
384
|
if (typeof typeahead !== "boolean") {
|
|
382
385
|
console.warn("Invalid typeahead option. Fallback: false.");
|
|
@@ -548,7 +551,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
548
551
|
if (char) {
|
|
549
552
|
keys.add(char);
|
|
550
553
|
saveAttributes(focusable, "aria-keyshortcuts");
|
|
551
|
-
|
|
554
|
+
addAttributeToken(focusable, "aria-keyshortcuts", char, {
|
|
552
555
|
caseInsensitive: true
|
|
553
556
|
});
|
|
554
557
|
}
|
|
@@ -588,7 +591,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
588
591
|
* Lightweight roving tabindex utility with fully focus management.
|
|
589
592
|
* Designed for accessible menus, tabs, toolbars, and composite widgets.
|
|
590
593
|
*
|
|
591
|
-
* @version 3.1.
|
|
594
|
+
* @version 3.1.21
|
|
592
595
|
* @author Yusuke Kamiyamane
|
|
593
596
|
* @license MIT
|
|
594
597
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -596,15 +599,15 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
596
599
|
*/
|
|
597
600
|
/*! Bundled license information:
|
|
598
601
|
|
|
599
|
-
@y14e/
|
|
602
|
+
@y14e/attribute-util/dist/index.js:
|
|
600
603
|
(**
|
|
601
|
-
*
|
|
604
|
+
* Attribute Util
|
|
602
605
|
*
|
|
603
|
-
* @version
|
|
606
|
+
* @version 2.0.0
|
|
604
607
|
* @author Yusuke Kamiyamane
|
|
605
608
|
* @license MIT
|
|
606
609
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
607
|
-
* @see {@link https://github.com/y14e/
|
|
610
|
+
* @see {@link https://github.com/y14e/attribute-util}
|
|
608
611
|
*)
|
|
609
612
|
|
|
610
613
|
power-focusable/dist/index.js:
|
|
@@ -613,7 +616,7 @@ power-focusable/dist/index.js:
|
|
|
613
616
|
* High-precision focus management utility with full composed tree support.
|
|
614
617
|
* Handles complex focus rules including tabindex ordering, radio groups, inert.
|
|
615
618
|
*
|
|
616
|
-
* @version 4.3.
|
|
619
|
+
* @version 4.3.23
|
|
617
620
|
* @author Yusuke Kamiyamane
|
|
618
621
|
* @license MIT
|
|
619
622
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.bundle.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
// node_modules/@y14e/
|
|
1
|
+
// node_modules/@y14e/attribute-util/dist/index.js
|
|
2
2
|
var DEFAULT_PARSER = (value) => value.split(/\s+/);
|
|
3
3
|
var DEFAULT_SERIALIZER = (tokens) => tokens.join(" ");
|
|
4
|
-
function
|
|
5
|
-
const value = element.getAttribute(
|
|
4
|
+
function addAttributeToken(element, name, token, options = {}) {
|
|
5
|
+
const value = element.getAttribute(name)?.trim();
|
|
6
6
|
const {
|
|
7
7
|
caseInsensitive = false,
|
|
8
8
|
parse = DEFAULT_PARSER,
|
|
@@ -13,12 +13,12 @@ function addTokenToAttribute(element, attribute, token, options = {}) {
|
|
|
13
13
|
const lower = token.toLowerCase();
|
|
14
14
|
if (tokens.every((token2) => token2.toLowerCase() !== lower)) {
|
|
15
15
|
tokens.push(token);
|
|
16
|
-
element.setAttribute(
|
|
16
|
+
element.setAttribute(name, serialize(tokens));
|
|
17
17
|
}
|
|
18
18
|
} else {
|
|
19
19
|
const set = new Set(tokens);
|
|
20
20
|
set.add(token);
|
|
21
|
-
element.setAttribute(
|
|
21
|
+
element.setAttribute(name, serialize([...set]));
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
var snapshots = /* @__PURE__ */ new WeakMap();
|
|
@@ -28,22 +28,22 @@ function restoreAttributes(element_or_elements) {
|
|
|
28
28
|
if (!snapshot) {
|
|
29
29
|
continue;
|
|
30
30
|
}
|
|
31
|
-
for (const [
|
|
32
|
-
value === null ? element.removeAttribute(
|
|
31
|
+
for (const [name, value] of snapshot.entries()) {
|
|
32
|
+
value === null ? element.removeAttribute(name) : element.setAttribute(name, value);
|
|
33
33
|
}
|
|
34
34
|
snapshots.delete(element);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
function saveAttributes(element_or_elements,
|
|
38
|
-
const
|
|
37
|
+
function saveAttributes(element_or_elements, name_or_names) {
|
|
38
|
+
const names = Array.isArray(name_or_names) ? name_or_names : [name_or_names];
|
|
39
39
|
(Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]).forEach((element) => {
|
|
40
40
|
let snapshot = snapshots.get(element);
|
|
41
41
|
if (!snapshot) {
|
|
42
42
|
snapshot = /* @__PURE__ */ new Map();
|
|
43
43
|
snapshots.set(element, snapshot);
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
snapshot.set(
|
|
45
|
+
names.forEach((name) => {
|
|
46
|
+
snapshot.set(name, element.getAttribute(name));
|
|
47
47
|
});
|
|
48
48
|
});
|
|
49
49
|
}
|
|
@@ -364,17 +364,20 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
364
364
|
noStart = false;
|
|
365
365
|
}
|
|
366
366
|
if (selector !== "") {
|
|
367
|
+
let hasError = false;
|
|
367
368
|
if (typeof selector !== "string" || !selector.trim()) {
|
|
368
|
-
|
|
369
|
-
selector = "";
|
|
369
|
+
hasError = true;
|
|
370
370
|
} else {
|
|
371
371
|
try {
|
|
372
|
-
container.querySelector(selector);
|
|
372
|
+
this.#container.querySelector(selector);
|
|
373
373
|
} catch {
|
|
374
|
-
|
|
375
|
-
selector = "";
|
|
374
|
+
hasError = true;
|
|
376
375
|
}
|
|
377
376
|
}
|
|
377
|
+
if (hasError) {
|
|
378
|
+
console.warn("Invalid selector. Fallback: no selector string.");
|
|
379
|
+
selector = "";
|
|
380
|
+
}
|
|
378
381
|
}
|
|
379
382
|
if (typeof typeahead !== "boolean") {
|
|
380
383
|
console.warn("Invalid typeahead option. Fallback: false.");
|
|
@@ -546,7 +549,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
546
549
|
if (char) {
|
|
547
550
|
keys.add(char);
|
|
548
551
|
saveAttributes(focusable, "aria-keyshortcuts");
|
|
549
|
-
|
|
552
|
+
addAttributeToken(focusable, "aria-keyshortcuts", char, {
|
|
550
553
|
caseInsensitive: true
|
|
551
554
|
});
|
|
552
555
|
}
|
|
@@ -586,7 +589,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
586
589
|
* Lightweight roving tabindex utility with fully focus management.
|
|
587
590
|
* Designed for accessible menus, tabs, toolbars, and composite widgets.
|
|
588
591
|
*
|
|
589
|
-
* @version 3.1.
|
|
592
|
+
* @version 3.1.21
|
|
590
593
|
* @author Yusuke Kamiyamane
|
|
591
594
|
* @license MIT
|
|
592
595
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -594,15 +597,15 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
594
597
|
*/
|
|
595
598
|
/*! Bundled license information:
|
|
596
599
|
|
|
597
|
-
@y14e/
|
|
600
|
+
@y14e/attribute-util/dist/index.js:
|
|
598
601
|
(**
|
|
599
|
-
*
|
|
602
|
+
* Attribute Util
|
|
600
603
|
*
|
|
601
|
-
* @version
|
|
604
|
+
* @version 2.0.0
|
|
602
605
|
* @author Yusuke Kamiyamane
|
|
603
606
|
* @license MIT
|
|
604
607
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
605
|
-
* @see {@link https://github.com/y14e/
|
|
608
|
+
* @see {@link https://github.com/y14e/attribute-util}
|
|
606
609
|
*)
|
|
607
610
|
|
|
608
611
|
power-focusable/dist/index.js:
|
|
@@ -611,7 +614,7 @@ power-focusable/dist/index.js:
|
|
|
611
614
|
* High-precision focus management utility with full composed tree support.
|
|
612
615
|
* Handles complex focus rules including tabindex ordering, radio groups, inert.
|
|
613
616
|
*
|
|
614
|
-
* @version 4.3.
|
|
617
|
+
* @version 4.3.23
|
|
615
618
|
* @author Yusuke Kamiyamane
|
|
616
619
|
* @license MIT
|
|
617
620
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var util = require('@y14e/attribute-util');
|
|
4
|
+
var pf = require('power-focusable');
|
|
5
|
+
|
|
6
|
+
function _interopNamespace(e) {
|
|
7
|
+
if (e && e.__esModule) return e;
|
|
8
|
+
var n = Object.create(null);
|
|
9
|
+
if (e) {
|
|
10
|
+
Object.keys(e).forEach(function (k) {
|
|
11
|
+
if (k !== 'default') {
|
|
12
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return e[k]; }
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
n.default = e;
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var util__namespace = /*#__PURE__*/_interopNamespace(util);
|
|
25
|
+
var pf__namespace = /*#__PURE__*/_interopNamespace(pf);
|
|
5
26
|
|
|
6
27
|
// src/index.ts
|
|
7
28
|
function createRovingTabIndex(container, options = {}) {
|
|
@@ -50,17 +71,20 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
50
71
|
noStart = false;
|
|
51
72
|
}
|
|
52
73
|
if (selector !== "") {
|
|
74
|
+
let hasError = false;
|
|
53
75
|
if (typeof selector !== "string" || !selector.trim()) {
|
|
54
|
-
|
|
55
|
-
selector = "";
|
|
76
|
+
hasError = true;
|
|
56
77
|
} else {
|
|
57
78
|
try {
|
|
58
|
-
container.querySelector(selector);
|
|
79
|
+
this.#container.querySelector(selector);
|
|
59
80
|
} catch {
|
|
60
|
-
|
|
61
|
-
selector = "";
|
|
81
|
+
hasError = true;
|
|
62
82
|
}
|
|
63
83
|
}
|
|
84
|
+
if (hasError) {
|
|
85
|
+
console.warn("Invalid selector. Fallback: no selector string.");
|
|
86
|
+
selector = "";
|
|
87
|
+
}
|
|
64
88
|
}
|
|
65
89
|
if (typeof typeahead !== "boolean") {
|
|
66
90
|
console.warn("Invalid typeahead option. Fallback: false.");
|
|
@@ -91,13 +115,13 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
91
115
|
this.#controller = null;
|
|
92
116
|
this.#focusables.forEach((focusable) => {
|
|
93
117
|
_RovingTabIndex.#initialized.delete(focusable);
|
|
94
|
-
|
|
118
|
+
util__namespace.restoreAttributes(focusable);
|
|
95
119
|
});
|
|
96
120
|
this.#focusables.clear();
|
|
97
121
|
this.#focusablesByFirstChar.clear();
|
|
98
122
|
}
|
|
99
123
|
#initialize() {
|
|
100
|
-
this.#update(
|
|
124
|
+
this.#update(pf__namespace.getActiveElement());
|
|
101
125
|
this.#controller = new AbortController();
|
|
102
126
|
const { signal } = this.#controller;
|
|
103
127
|
this.#container.addEventListener("focusin", this.#onFocusIn, { signal });
|
|
@@ -144,7 +168,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
144
168
|
const candidates = this.#getFocusables().filter(
|
|
145
169
|
(focusable2) => this.#focusables.has(focusable2)
|
|
146
170
|
);
|
|
147
|
-
const active =
|
|
171
|
+
const active = pf__namespace.getActiveElement();
|
|
148
172
|
if (!(active instanceof Element)) {
|
|
149
173
|
return;
|
|
150
174
|
}
|
|
@@ -189,14 +213,14 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
189
213
|
}
|
|
190
214
|
}
|
|
191
215
|
const focusable = focusables.at(newIndex);
|
|
192
|
-
focusable &&
|
|
216
|
+
focusable && pf__namespace.focusElement(focusable);
|
|
193
217
|
};
|
|
194
218
|
#update(active) {
|
|
195
219
|
const current = new Set(this.#getFocusables());
|
|
196
220
|
for (const focusable of this.#focusables) {
|
|
197
221
|
if (!current.has(focusable)) {
|
|
198
222
|
_RovingTabIndex.#initialized.delete(focusable);
|
|
199
|
-
|
|
223
|
+
util__namespace.restoreAttributes(focusable);
|
|
200
224
|
this.#focusables.delete(focusable);
|
|
201
225
|
for (const [key, focusables] of this.#focusablesByFirstChar) {
|
|
202
226
|
const index = focusables.indexOf(focusable);
|
|
@@ -218,7 +242,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
218
242
|
this.#focusables.add(focusable);
|
|
219
243
|
_RovingTabIndex.#initialized.add(focusable);
|
|
220
244
|
if (!navigationOnly) {
|
|
221
|
-
|
|
245
|
+
util__namespace.saveAttributes(focusable, "tabindex");
|
|
222
246
|
focusable.setAttribute("tabindex", "-1");
|
|
223
247
|
}
|
|
224
248
|
if (!typeahead) {
|
|
@@ -231,8 +255,8 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
231
255
|
);
|
|
232
256
|
if (char) {
|
|
233
257
|
keys.add(char);
|
|
234
|
-
|
|
235
|
-
|
|
258
|
+
util__namespace.saveAttributes(focusable, "aria-keyshortcuts");
|
|
259
|
+
util__namespace.addAttributeToken(focusable, "aria-keyshortcuts", char, {
|
|
236
260
|
caseInsensitive: true
|
|
237
261
|
});
|
|
238
262
|
}
|
|
@@ -259,7 +283,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
259
283
|
return (element) => !selector || [...this.#container.querySelectorAll(selector)].includes(element);
|
|
260
284
|
}
|
|
261
285
|
#getFocusables() {
|
|
262
|
-
return
|
|
286
|
+
return pf__namespace.getFocusables(this.#container, {
|
|
263
287
|
composed: true,
|
|
264
288
|
filter: this.#selectorFilter,
|
|
265
289
|
skipNegativeTabIndexCheck: !this.#settings.navigationOnly,
|
|
@@ -272,7 +296,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
272
296
|
* Lightweight roving tabindex utility with fully focus management.
|
|
273
297
|
* Designed for accessible menus, tabs, toolbars, and composite widgets.
|
|
274
298
|
*
|
|
275
|
-
* @version 3.1.
|
|
299
|
+
* @version 3.1.21
|
|
276
300
|
* @author Yusuke Kamiyamane
|
|
277
301
|
* @license MIT
|
|
278
302
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.d.cts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Lightweight roving tabindex utility with fully focus management.
|
|
4
4
|
* Designed for accessible menus, tabs, toolbars, and composite widgets.
|
|
5
5
|
*
|
|
6
|
-
* @version 3.1.
|
|
6
|
+
* @version 3.1.21
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Lightweight roving tabindex utility with fully focus management.
|
|
4
4
|
* Designed for accessible menus, tabs, toolbars, and composite widgets.
|
|
5
5
|
*
|
|
6
|
-
* @version 3.1.
|
|
6
|
+
* @version 3.1.21
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import * as util from '@y14e/attribute-util';
|
|
2
|
+
import * as pf from 'power-focusable';
|
|
3
3
|
|
|
4
4
|
// src/index.ts
|
|
5
5
|
function createRovingTabIndex(container, options = {}) {
|
|
@@ -48,17 +48,20 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
48
48
|
noStart = false;
|
|
49
49
|
}
|
|
50
50
|
if (selector !== "") {
|
|
51
|
+
let hasError = false;
|
|
51
52
|
if (typeof selector !== "string" || !selector.trim()) {
|
|
52
|
-
|
|
53
|
-
selector = "";
|
|
53
|
+
hasError = true;
|
|
54
54
|
} else {
|
|
55
55
|
try {
|
|
56
|
-
container.querySelector(selector);
|
|
56
|
+
this.#container.querySelector(selector);
|
|
57
57
|
} catch {
|
|
58
|
-
|
|
59
|
-
selector = "";
|
|
58
|
+
hasError = true;
|
|
60
59
|
}
|
|
61
60
|
}
|
|
61
|
+
if (hasError) {
|
|
62
|
+
console.warn("Invalid selector. Fallback: no selector string.");
|
|
63
|
+
selector = "";
|
|
64
|
+
}
|
|
62
65
|
}
|
|
63
66
|
if (typeof typeahead !== "boolean") {
|
|
64
67
|
console.warn("Invalid typeahead option. Fallback: false.");
|
|
@@ -89,13 +92,13 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
89
92
|
this.#controller = null;
|
|
90
93
|
this.#focusables.forEach((focusable) => {
|
|
91
94
|
_RovingTabIndex.#initialized.delete(focusable);
|
|
92
|
-
restoreAttributes(focusable);
|
|
95
|
+
util.restoreAttributes(focusable);
|
|
93
96
|
});
|
|
94
97
|
this.#focusables.clear();
|
|
95
98
|
this.#focusablesByFirstChar.clear();
|
|
96
99
|
}
|
|
97
100
|
#initialize() {
|
|
98
|
-
this.#update(getActiveElement());
|
|
101
|
+
this.#update(pf.getActiveElement());
|
|
99
102
|
this.#controller = new AbortController();
|
|
100
103
|
const { signal } = this.#controller;
|
|
101
104
|
this.#container.addEventListener("focusin", this.#onFocusIn, { signal });
|
|
@@ -142,7 +145,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
142
145
|
const candidates = this.#getFocusables().filter(
|
|
143
146
|
(focusable2) => this.#focusables.has(focusable2)
|
|
144
147
|
);
|
|
145
|
-
const active = getActiveElement();
|
|
148
|
+
const active = pf.getActiveElement();
|
|
146
149
|
if (!(active instanceof Element)) {
|
|
147
150
|
return;
|
|
148
151
|
}
|
|
@@ -187,14 +190,14 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
187
190
|
}
|
|
188
191
|
}
|
|
189
192
|
const focusable = focusables.at(newIndex);
|
|
190
|
-
focusable && focusElement(focusable);
|
|
193
|
+
focusable && pf.focusElement(focusable);
|
|
191
194
|
};
|
|
192
195
|
#update(active) {
|
|
193
196
|
const current = new Set(this.#getFocusables());
|
|
194
197
|
for (const focusable of this.#focusables) {
|
|
195
198
|
if (!current.has(focusable)) {
|
|
196
199
|
_RovingTabIndex.#initialized.delete(focusable);
|
|
197
|
-
restoreAttributes(focusable);
|
|
200
|
+
util.restoreAttributes(focusable);
|
|
198
201
|
this.#focusables.delete(focusable);
|
|
199
202
|
for (const [key, focusables] of this.#focusablesByFirstChar) {
|
|
200
203
|
const index = focusables.indexOf(focusable);
|
|
@@ -216,7 +219,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
216
219
|
this.#focusables.add(focusable);
|
|
217
220
|
_RovingTabIndex.#initialized.add(focusable);
|
|
218
221
|
if (!navigationOnly) {
|
|
219
|
-
saveAttributes(focusable, "tabindex");
|
|
222
|
+
util.saveAttributes(focusable, "tabindex");
|
|
220
223
|
focusable.setAttribute("tabindex", "-1");
|
|
221
224
|
}
|
|
222
225
|
if (!typeahead) {
|
|
@@ -229,8 +232,8 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
229
232
|
);
|
|
230
233
|
if (char) {
|
|
231
234
|
keys.add(char);
|
|
232
|
-
saveAttributes(focusable, "aria-keyshortcuts");
|
|
233
|
-
|
|
235
|
+
util.saveAttributes(focusable, "aria-keyshortcuts");
|
|
236
|
+
util.addAttributeToken(focusable, "aria-keyshortcuts", char, {
|
|
234
237
|
caseInsensitive: true
|
|
235
238
|
});
|
|
236
239
|
}
|
|
@@ -257,7 +260,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
257
260
|
return (element) => !selector || [...this.#container.querySelectorAll(selector)].includes(element);
|
|
258
261
|
}
|
|
259
262
|
#getFocusables() {
|
|
260
|
-
return getFocusables(this.#container, {
|
|
263
|
+
return pf.getFocusables(this.#container, {
|
|
261
264
|
composed: true,
|
|
262
265
|
filter: this.#selectorFilter,
|
|
263
266
|
skipNegativeTabIndexCheck: !this.#settings.navigationOnly,
|
|
@@ -270,7 +273,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
270
273
|
* Lightweight roving tabindex utility with fully focus management.
|
|
271
274
|
* Designed for accessible menus, tabs, toolbars, and composite widgets.
|
|
272
275
|
*
|
|
273
|
-
* @version 3.1.
|
|
276
|
+
* @version 3.1.21
|
|
274
277
|
* @author Yusuke Kamiyamane
|
|
275
278
|
* @license MIT
|
|
276
279
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@y14e/roving-tabindex",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.21",
|
|
4
4
|
"description": "Lightweight roving tabindex utility with fully focus management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"node": ">=18"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@y14e/
|
|
60
|
-
"power-focusable": "^4.3.
|
|
59
|
+
"@y14e/attribute-util": "^2.0.0",
|
|
60
|
+
"power-focusable": "^4.3.23"
|
|
61
61
|
}
|
|
62
62
|
}
|