@y14e/roving-tabindex 2.0.3 → 2.0.5

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@2.0.3';
13
+ import { createRovingTabIndex } from '@y14e/roving-tabindex@2.0.5';
14
14
 
15
15
  // CDNs
16
- import { createRovingTabIndex } from 'https://esm.sh/@y14e/roving-tabindex@2.0.3';
16
+ import { createRovingTabIndex } from 'https://esm.sh/@y14e/roving-tabindex@2.0.5';
17
17
  // or
18
- import { createRovingTabIndex } from 'https://cdn.jsdelivr.net/npm/@y14e/roving-tabindex@2.0.3/+esm';
18
+ import { createRovingTabIndex } from 'https://cdn.jsdelivr.net/npm/@y14e/roving-tabindex@2.0.5/+esm';
19
19
  // or
20
- import { createRovingTabIndex } from 'https://esm.unpkg.com/@y14e/roving-tabindex@2.0.3';
20
+ import { createRovingTabIndex } from 'https://esm.unpkg.com/@y14e/roving-tabindex@2.0.5';
21
21
  ```
22
22
 
23
23
  ## 📦 APIs
package/dist/index.cjs CHANGED
@@ -312,7 +312,7 @@ function createRovingTabIndex(container, options = {}) {
312
312
  console.warn("Invalid navigationOnly option. Fallback: false.");
313
313
  navigationOnly = false;
314
314
  }
315
- if (typeof selector !== "undefined" && typeof selector !== "string") {
315
+ if (typeof selector !== "undefined" && (typeof selector !== "string" || !selector.trim())) {
316
316
  console.warn(
317
317
  "Invalid selector. Fallback: all focusable elements (undefined)."
318
318
  );
@@ -327,10 +327,10 @@ function createRovingTabIndex(container, options = {}) {
327
327
  wrap = false;
328
328
  }
329
329
  const settings = { navigationOnly, typeahead, wrap };
330
- if (direction !== void 0) {
330
+ if (direction) {
331
331
  Object.assign(settings, { direction });
332
332
  }
333
- if (selector !== void 0) {
333
+ if (selector) {
334
334
  Object.assign(settings, { selector });
335
335
  }
336
336
  const roving = new RovingTabIndex(container, settings);
@@ -365,12 +365,24 @@ var RovingTabIndex = class {
365
365
  #initialize() {
366
366
  this.#update(document.activeElement);
367
367
  this.#controller = new AbortController();
368
+ const { signal } = this.#controller;
369
+ document.addEventListener("focusin", this.#onFocusIn, {
370
+ capture: true,
371
+ signal
372
+ });
368
373
  document.addEventListener("keydown", this.#onKeyDown, {
369
374
  capture: true,
370
- signal: this.#controller.signal
375
+ signal
371
376
  });
372
377
  this.#container.setAttribute("data-roving-tabindex-initialized", "");
373
378
  }
379
+ #onFocusIn = (event) => {
380
+ const { target } = event;
381
+ if (!(target instanceof Element) || !this.#focusables.has(target)) {
382
+ return;
383
+ }
384
+ this.#update(target);
385
+ };
374
386
  #onKeyDown = (event) => {
375
387
  if (!event.composedPath().includes(this.#container)) {
376
388
  return;
@@ -435,7 +447,6 @@ var RovingTabIndex = class {
435
447
  if (!focusable) {
436
448
  return;
437
449
  }
438
- this.#update(focusable);
439
450
  focusElement(focusable);
440
451
  };
441
452
  #update(active) {
@@ -522,7 +533,7 @@ function getActiveElement() {
522
533
  * Lightweight roving tabindex utility with fully focus management.
523
534
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
524
535
  *
525
- * @version 2.0.3
536
+ * @version 2.0.5
526
537
  * @author Yusuke Kamiyamane
527
538
  * @license MIT
528
539
  * @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 2.0.3
6
+ * @version 2.0.5
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 2.0.3
6
+ * @version 2.0.5
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -310,7 +310,7 @@ function createRovingTabIndex(container, options = {}) {
310
310
  console.warn("Invalid navigationOnly option. Fallback: false.");
311
311
  navigationOnly = false;
312
312
  }
313
- if (typeof selector !== "undefined" && typeof selector !== "string") {
313
+ if (typeof selector !== "undefined" && (typeof selector !== "string" || !selector.trim())) {
314
314
  console.warn(
315
315
  "Invalid selector. Fallback: all focusable elements (undefined)."
316
316
  );
@@ -325,10 +325,10 @@ function createRovingTabIndex(container, options = {}) {
325
325
  wrap = false;
326
326
  }
327
327
  const settings = { navigationOnly, typeahead, wrap };
328
- if (direction !== void 0) {
328
+ if (direction) {
329
329
  Object.assign(settings, { direction });
330
330
  }
331
- if (selector !== void 0) {
331
+ if (selector) {
332
332
  Object.assign(settings, { selector });
333
333
  }
334
334
  const roving = new RovingTabIndex(container, settings);
@@ -363,12 +363,24 @@ var RovingTabIndex = class {
363
363
  #initialize() {
364
364
  this.#update(document.activeElement);
365
365
  this.#controller = new AbortController();
366
+ const { signal } = this.#controller;
367
+ document.addEventListener("focusin", this.#onFocusIn, {
368
+ capture: true,
369
+ signal
370
+ });
366
371
  document.addEventListener("keydown", this.#onKeyDown, {
367
372
  capture: true,
368
- signal: this.#controller.signal
373
+ signal
369
374
  });
370
375
  this.#container.setAttribute("data-roving-tabindex-initialized", "");
371
376
  }
377
+ #onFocusIn = (event) => {
378
+ const { target } = event;
379
+ if (!(target instanceof Element) || !this.#focusables.has(target)) {
380
+ return;
381
+ }
382
+ this.#update(target);
383
+ };
372
384
  #onKeyDown = (event) => {
373
385
  if (!event.composedPath().includes(this.#container)) {
374
386
  return;
@@ -433,7 +445,6 @@ var RovingTabIndex = class {
433
445
  if (!focusable) {
434
446
  return;
435
447
  }
436
- this.#update(focusable);
437
448
  focusElement(focusable);
438
449
  };
439
450
  #update(active) {
@@ -520,7 +531,7 @@ function getActiveElement() {
520
531
  * Lightweight roving tabindex utility with fully focus management.
521
532
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
522
533
  *
523
- * @version 2.0.3
534
+ * @version 2.0.5
524
535
  * @author Yusuke Kamiyamane
525
536
  * @license MIT
526
537
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/roving-tabindex",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "Lightweight roving tabindex utility with fully focus management",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",