@y14e/roving-tabindex 3.0.8 → 3.0.9

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 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@3.0.8';
13
+ import { createRovingTabIndex } from '@y14e/roving-tabindex@3.0.9';
14
14
 
15
15
  // CDNs
16
- import { createRovingTabIndex } from 'https://esm.sh/@y14e/roving-tabindex@3.0.8';
16
+ import { createRovingTabIndex } from 'https://esm.sh/@y14e/roving-tabindex@3.0.9';
17
17
  // or
18
- import { createRovingTabIndex } from 'https://cdn.jsdelivr.net/npm/@y14e/roving-tabindex@3.0.8/+esm';
18
+ import { createRovingTabIndex } from 'https://cdn.jsdelivr.net/npm/@y14e/roving-tabindex@3.0.9/+esm';
19
19
  // or
20
- import { createRovingTabIndex } from 'https://esm.unpkg.com/@y14e/roving-tabindex@3.0.8';
20
+ import { createRovingTabIndex } from 'https://esm.unpkg.com/@y14e/roving-tabindex@3.0.9';
21
21
  ```
22
22
 
23
23
  ## 📦 APIs
package/dist/index.cjs CHANGED
@@ -297,6 +297,7 @@ function createRovingTabIndex(container, options = {}) {
297
297
  const roving = new RovingTabIndex(container, options);
298
298
  return () => roving.destroy();
299
299
  }
300
+ var initialized = /* @__PURE__ */ new Set();
300
301
  var RovingTabIndex = class {
301
302
  #container;
302
303
  #settings;
@@ -372,13 +373,16 @@ var RovingTabIndex = class {
372
373
  }
373
374
  #initialize() {
374
375
  this.#update(document.activeElement);
376
+ if (!(this.#container instanceof HTMLElement)) {
377
+ return;
378
+ }
375
379
  this.#controller = new AbortController();
376
380
  const { signal } = this.#controller;
377
- document.addEventListener("focusin", this.#onFocusIn, {
381
+ this.#container.addEventListener("focusin", this.#onFocusIn, {
378
382
  capture: true,
379
383
  signal
380
384
  });
381
- document.addEventListener("keydown", this.#onKeyDown, {
385
+ this.#container.addEventListener("keydown", this.#onKeyDown, {
382
386
  capture: true,
383
387
  signal
384
388
  });
@@ -393,9 +397,6 @@ var RovingTabIndex = class {
393
397
  this.#settings.noMemory && !isFocusable2 ? this.#update(null) : isFocusable2 && this.#update(target);
394
398
  };
395
399
  #onKeyDown = (event) => {
396
- if (!event.composedPath().includes(this.#container)) {
397
- return;
398
- }
399
400
  const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
400
401
  if (altKey || ctrlKey || metaKey || shiftKey) {
401
402
  return;
@@ -469,10 +470,14 @@ var RovingTabIndex = class {
469
470
  }
470
471
  const { navigationOnly, noStart, typeahead } = this.#settings;
471
472
  for (const focusable of current) {
473
+ if (initialized.has(focusable)) {
474
+ throw new TypeError("Already initialized");
475
+ }
472
476
  if (this.#focusables.has(focusable)) {
473
477
  continue;
474
478
  }
475
479
  this.#focusables.add(focusable);
480
+ initialized.add(focusable);
476
481
  if (!navigationOnly) {
477
482
  saveAttributes([focusable], ["tabindex"]);
478
483
  focusable.setAttribute("tabindex", "-1");
@@ -528,7 +533,7 @@ var RovingTabIndex = class {
528
533
  * Lightweight roving tabindex utility with fully focus management.
529
534
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
530
535
  *
531
- * @version 3.0.8
536
+ * @version 3.0.9
532
537
  * @author Yusuke Kamiyamane
533
538
  * @license MIT
534
539
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.cts CHANGED
@@ -6,7 +6,7 @@ export { focusElement, getActiveElement, getFocusables } from 'power-focusable';
6
6
  * Lightweight roving tabindex utility with fully focus management.
7
7
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
8
8
  *
9
- * @version 3.0.8
9
+ * @version 3.0.9
10
10
  * @author Yusuke Kamiyamane
11
11
  * @license MIT
12
12
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ export { focusElement, getActiveElement, getFocusables } from 'power-focusable';
6
6
  * Lightweight roving tabindex utility with fully focus management.
7
7
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
8
8
  *
9
- * @version 3.0.8
9
+ * @version 3.0.9
10
10
  * @author Yusuke Kamiyamane
11
11
  * @license MIT
12
12
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -295,6 +295,7 @@ function createRovingTabIndex(container, options = {}) {
295
295
  const roving = new RovingTabIndex(container, options);
296
296
  return () => roving.destroy();
297
297
  }
298
+ var initialized = /* @__PURE__ */ new Set();
298
299
  var RovingTabIndex = class {
299
300
  #container;
300
301
  #settings;
@@ -370,13 +371,16 @@ var RovingTabIndex = class {
370
371
  }
371
372
  #initialize() {
372
373
  this.#update(document.activeElement);
374
+ if (!(this.#container instanceof HTMLElement)) {
375
+ return;
376
+ }
373
377
  this.#controller = new AbortController();
374
378
  const { signal } = this.#controller;
375
- document.addEventListener("focusin", this.#onFocusIn, {
379
+ this.#container.addEventListener("focusin", this.#onFocusIn, {
376
380
  capture: true,
377
381
  signal
378
382
  });
379
- document.addEventListener("keydown", this.#onKeyDown, {
383
+ this.#container.addEventListener("keydown", this.#onKeyDown, {
380
384
  capture: true,
381
385
  signal
382
386
  });
@@ -391,9 +395,6 @@ var RovingTabIndex = class {
391
395
  this.#settings.noMemory && !isFocusable2 ? this.#update(null) : isFocusable2 && this.#update(target);
392
396
  };
393
397
  #onKeyDown = (event) => {
394
- if (!event.composedPath().includes(this.#container)) {
395
- return;
396
- }
397
398
  const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
398
399
  if (altKey || ctrlKey || metaKey || shiftKey) {
399
400
  return;
@@ -467,10 +468,14 @@ var RovingTabIndex = class {
467
468
  }
468
469
  const { navigationOnly, noStart, typeahead } = this.#settings;
469
470
  for (const focusable of current) {
471
+ if (initialized.has(focusable)) {
472
+ throw new TypeError("Already initialized");
473
+ }
470
474
  if (this.#focusables.has(focusable)) {
471
475
  continue;
472
476
  }
473
477
  this.#focusables.add(focusable);
478
+ initialized.add(focusable);
474
479
  if (!navigationOnly) {
475
480
  saveAttributes([focusable], ["tabindex"]);
476
481
  focusable.setAttribute("tabindex", "-1");
@@ -526,7 +531,7 @@ var RovingTabIndex = class {
526
531
  * Lightweight roving tabindex utility with fully focus management.
527
532
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
528
533
  *
529
- * @version 3.0.8
534
+ * @version 3.0.9
530
535
  * @author Yusuke Kamiyamane
531
536
  * @license MIT
532
537
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/roving-tabindex",
3
- "version": "3.0.8",
3
+ "version": "3.0.9",
4
4
  "description": "Lightweight roving tabindex utility with fully focus management",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",