@y14e/roving-tabindex 2.2.1 → 3.0.1
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 +4 -9
- package/dist/index.cjs +9 -15
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +9 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,14 +10,14 @@ npm i @y14e/roving-tabindex
|
|
|
10
10
|
|
|
11
11
|
```ts
|
|
12
12
|
// npm
|
|
13
|
-
import { createRovingTabIndex } from '@y14e/roving-tabindex@
|
|
13
|
+
import { createRovingTabIndex } from '@y14e/roving-tabindex@3.0.1';
|
|
14
14
|
|
|
15
15
|
// CDNs
|
|
16
|
-
import { createRovingTabIndex } from 'https://esm.sh/@y14e/roving-tabindex@
|
|
16
|
+
import { createRovingTabIndex } from 'https://esm.sh/@y14e/roving-tabindex@3.0.1';
|
|
17
17
|
// or
|
|
18
|
-
import { createRovingTabIndex } from 'https://cdn.jsdelivr.net/npm/@y14e/roving-tabindex@
|
|
18
|
+
import { createRovingTabIndex } from 'https://cdn.jsdelivr.net/npm/@y14e/roving-tabindex@3.0.1/+esm';
|
|
19
19
|
// or
|
|
20
|
-
import { createRovingTabIndex } from 'https://esm.unpkg.com/@y14e/roving-tabindex@
|
|
20
|
+
import { createRovingTabIndex } from 'https://esm.unpkg.com/@y14e/roving-tabindex@3.0.1';
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## 📦 APIs
|
|
@@ -42,7 +42,6 @@ interface RovingTabIndexOptions {
|
|
|
42
42
|
navigationOnly?: boolean; // default: false
|
|
43
43
|
noMemory?: boolean; // default: false
|
|
44
44
|
noStart?: boolean; // default: false
|
|
45
|
-
noStopPropagation?: boolean; // default: false
|
|
46
45
|
selector?: string;
|
|
47
46
|
typeahead?: boolean; // default: false
|
|
48
47
|
wrap?: boolean; // default: false
|
|
@@ -61,10 +60,6 @@ If `true`, disables focus memory. Focus always starts from the first item.
|
|
|
61
60
|
|
|
62
61
|
If `true`, does not assign `tabindex="0"` to the first item during initialization.
|
|
63
62
|
|
|
64
|
-
### `noStopPropagation`
|
|
65
|
-
|
|
66
|
-
If `true`, keyboard navigation will not call `stopPropagation()`.
|
|
67
|
-
|
|
68
63
|
### `typeahead`
|
|
69
64
|
|
|
70
65
|
If `true`, enables character-based focus navigation. Typing a character moves focus to the next matching element.
|
package/dist/index.cjs
CHANGED
|
@@ -301,7 +301,6 @@ function createRovingTabIndex(container, options = {}) {
|
|
|
301
301
|
navigationOnly = false,
|
|
302
302
|
noMemory = false,
|
|
303
303
|
noStart = false,
|
|
304
|
-
noStopPropagation = false,
|
|
305
304
|
selector,
|
|
306
305
|
typeahead = false,
|
|
307
306
|
wrap = false
|
|
@@ -322,10 +321,6 @@ function createRovingTabIndex(container, options = {}) {
|
|
|
322
321
|
console.warn("Invalid noStart option. Fallback: false.");
|
|
323
322
|
noStart = false;
|
|
324
323
|
}
|
|
325
|
-
if (typeof noStopPropagation !== "boolean") {
|
|
326
|
-
console.warn("Invalid noStopPropagation option. Fallback: false.");
|
|
327
|
-
noStopPropagation = false;
|
|
328
|
-
}
|
|
329
324
|
if (typeof selector !== "undefined" && (typeof selector !== "string" || !selector.trim())) {
|
|
330
325
|
console.warn(
|
|
331
326
|
"Invalid selector. Fallback: all focusable elements (undefined)."
|
|
@@ -344,7 +339,6 @@ function createRovingTabIndex(container, options = {}) {
|
|
|
344
339
|
navigationOnly,
|
|
345
340
|
noMemory,
|
|
346
341
|
noStart,
|
|
347
|
-
noStopPropagation,
|
|
348
342
|
typeahead,
|
|
349
343
|
wrap
|
|
350
344
|
};
|
|
@@ -413,7 +407,7 @@ var RovingTabIndex = class {
|
|
|
413
407
|
if (altKey || ctrlKey || metaKey || shiftKey) {
|
|
414
408
|
return;
|
|
415
409
|
}
|
|
416
|
-
const { direction,
|
|
410
|
+
const { direction, typeahead, wrap } = this.#options;
|
|
417
411
|
const isBoth = !direction;
|
|
418
412
|
const isHorizontal = direction === "horizontal";
|
|
419
413
|
if (![
|
|
@@ -435,10 +429,8 @@ var RovingTabIndex = class {
|
|
|
435
429
|
return;
|
|
436
430
|
}
|
|
437
431
|
event.preventDefault();
|
|
438
|
-
!noStopPropagation && event.stopPropagation();
|
|
439
432
|
const currentIndex = current.indexOf(active);
|
|
440
|
-
let
|
|
441
|
-
let newIndex = currentIndex;
|
|
433
|
+
let newIndex;
|
|
442
434
|
let target = current;
|
|
443
435
|
switch (key) {
|
|
444
436
|
case "End":
|
|
@@ -448,15 +440,17 @@ var RovingTabIndex = class {
|
|
|
448
440
|
newIndex = 0;
|
|
449
441
|
break;
|
|
450
442
|
case "ArrowLeft":
|
|
451
|
-
case "ArrowUp":
|
|
452
|
-
rawIndex = currentIndex - 1;
|
|
443
|
+
case "ArrowUp": {
|
|
444
|
+
const rawIndex = currentIndex - 1;
|
|
453
445
|
newIndex = wrap ? rawIndex : Math.max(rawIndex, 0);
|
|
454
446
|
break;
|
|
447
|
+
}
|
|
455
448
|
case "ArrowRight":
|
|
456
|
-
case "ArrowDown":
|
|
457
|
-
rawIndex = currentIndex + 1;
|
|
449
|
+
case "ArrowDown": {
|
|
450
|
+
const rawIndex = currentIndex + 1;
|
|
458
451
|
newIndex = wrap ? rawIndex % current.length : Math.min(rawIndex, current.length - 1);
|
|
459
452
|
break;
|
|
453
|
+
}
|
|
460
454
|
default: {
|
|
461
455
|
target = this.#focusablesByFirstChar.get(key.toUpperCase()) ?? [];
|
|
462
456
|
const foundIndex = target.findIndex(
|
|
@@ -553,7 +547,7 @@ function getActiveElement() {
|
|
|
553
547
|
* Lightweight roving tabindex utility with fully focus management.
|
|
554
548
|
* Designed for accessible menus, tabs, toolbars, and composite widgets.
|
|
555
549
|
*
|
|
556
|
-
* @version
|
|
550
|
+
* @version 3.0.1
|
|
557
551
|
* @author Yusuke Kamiyamane
|
|
558
552
|
* @license MIT
|
|
559
553
|
* @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
|
|
6
|
+
* @version 3.0.1
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -14,7 +14,6 @@ interface RovingTabIndexOptions {
|
|
|
14
14
|
readonly navigationOnly?: boolean;
|
|
15
15
|
readonly noMemory?: boolean;
|
|
16
16
|
readonly noStart?: boolean;
|
|
17
|
-
readonly noStopPropagation?: boolean;
|
|
18
17
|
readonly selector?: string;
|
|
19
18
|
readonly typeahead?: boolean;
|
|
20
19
|
readonly wrap?: boolean;
|
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
|
|
6
|
+
* @version 3.0.1
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -14,7 +14,6 @@ interface RovingTabIndexOptions {
|
|
|
14
14
|
readonly navigationOnly?: boolean;
|
|
15
15
|
readonly noMemory?: boolean;
|
|
16
16
|
readonly noStart?: boolean;
|
|
17
|
-
readonly noStopPropagation?: boolean;
|
|
18
17
|
readonly selector?: string;
|
|
19
18
|
readonly typeahead?: boolean;
|
|
20
19
|
readonly wrap?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -299,7 +299,6 @@ function createRovingTabIndex(container, options = {}) {
|
|
|
299
299
|
navigationOnly = false,
|
|
300
300
|
noMemory = false,
|
|
301
301
|
noStart = false,
|
|
302
|
-
noStopPropagation = false,
|
|
303
302
|
selector,
|
|
304
303
|
typeahead = false,
|
|
305
304
|
wrap = false
|
|
@@ -320,10 +319,6 @@ function createRovingTabIndex(container, options = {}) {
|
|
|
320
319
|
console.warn("Invalid noStart option. Fallback: false.");
|
|
321
320
|
noStart = false;
|
|
322
321
|
}
|
|
323
|
-
if (typeof noStopPropagation !== "boolean") {
|
|
324
|
-
console.warn("Invalid noStopPropagation option. Fallback: false.");
|
|
325
|
-
noStopPropagation = false;
|
|
326
|
-
}
|
|
327
322
|
if (typeof selector !== "undefined" && (typeof selector !== "string" || !selector.trim())) {
|
|
328
323
|
console.warn(
|
|
329
324
|
"Invalid selector. Fallback: all focusable elements (undefined)."
|
|
@@ -342,7 +337,6 @@ function createRovingTabIndex(container, options = {}) {
|
|
|
342
337
|
navigationOnly,
|
|
343
338
|
noMemory,
|
|
344
339
|
noStart,
|
|
345
|
-
noStopPropagation,
|
|
346
340
|
typeahead,
|
|
347
341
|
wrap
|
|
348
342
|
};
|
|
@@ -411,7 +405,7 @@ var RovingTabIndex = class {
|
|
|
411
405
|
if (altKey || ctrlKey || metaKey || shiftKey) {
|
|
412
406
|
return;
|
|
413
407
|
}
|
|
414
|
-
const { direction,
|
|
408
|
+
const { direction, typeahead, wrap } = this.#options;
|
|
415
409
|
const isBoth = !direction;
|
|
416
410
|
const isHorizontal = direction === "horizontal";
|
|
417
411
|
if (![
|
|
@@ -433,10 +427,8 @@ var RovingTabIndex = class {
|
|
|
433
427
|
return;
|
|
434
428
|
}
|
|
435
429
|
event.preventDefault();
|
|
436
|
-
!noStopPropagation && event.stopPropagation();
|
|
437
430
|
const currentIndex = current.indexOf(active);
|
|
438
|
-
let
|
|
439
|
-
let newIndex = currentIndex;
|
|
431
|
+
let newIndex;
|
|
440
432
|
let target = current;
|
|
441
433
|
switch (key) {
|
|
442
434
|
case "End":
|
|
@@ -446,15 +438,17 @@ var RovingTabIndex = class {
|
|
|
446
438
|
newIndex = 0;
|
|
447
439
|
break;
|
|
448
440
|
case "ArrowLeft":
|
|
449
|
-
case "ArrowUp":
|
|
450
|
-
rawIndex = currentIndex - 1;
|
|
441
|
+
case "ArrowUp": {
|
|
442
|
+
const rawIndex = currentIndex - 1;
|
|
451
443
|
newIndex = wrap ? rawIndex : Math.max(rawIndex, 0);
|
|
452
444
|
break;
|
|
445
|
+
}
|
|
453
446
|
case "ArrowRight":
|
|
454
|
-
case "ArrowDown":
|
|
455
|
-
rawIndex = currentIndex + 1;
|
|
447
|
+
case "ArrowDown": {
|
|
448
|
+
const rawIndex = currentIndex + 1;
|
|
456
449
|
newIndex = wrap ? rawIndex % current.length : Math.min(rawIndex, current.length - 1);
|
|
457
450
|
break;
|
|
451
|
+
}
|
|
458
452
|
default: {
|
|
459
453
|
target = this.#focusablesByFirstChar.get(key.toUpperCase()) ?? [];
|
|
460
454
|
const foundIndex = target.findIndex(
|
|
@@ -551,7 +545,7 @@ function getActiveElement() {
|
|
|
551
545
|
* Lightweight roving tabindex utility with fully focus management.
|
|
552
546
|
* Designed for accessible menus, tabs, toolbars, and composite widgets.
|
|
553
547
|
*
|
|
554
|
-
* @version
|
|
548
|
+
* @version 3.0.1
|
|
555
549
|
* @author Yusuke Kamiyamane
|
|
556
550
|
* @license MIT
|
|
557
551
|
* @copyright Copyright (c) Yusuke Kamiyamane
|