@y14e/portal 1.2.13 → 1.2.14

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/portal
10
10
 
11
11
  ```ts
12
12
  // npm
13
- import { createPortal } from '@y14e/portal@1.2.13';
13
+ import { createPortal } from '@y14e/portal@1.2.14';
14
14
 
15
15
  // CDNs
16
- import { createPortal } from 'https://esm.sh/@y14e/portal@1.2.13';
16
+ import { createPortal } from 'https://esm.sh/@y14e/portal@1.2.14';
17
17
  // or
18
- import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@1.2.13/+esm';
18
+ import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@1.2.14/+esm';
19
19
  // or
20
- import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@1.2.13';
20
+ import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@1.2.14';
21
21
  ```
22
22
 
23
23
  ## 📦 APIs
package/dist/index.cjs CHANGED
@@ -457,7 +457,15 @@ var Portal = class {
457
457
  }
458
458
  this.#update();
459
459
  const first = [...this.#focusables][0];
460
- first && focusElement(first);
460
+ if (first) {
461
+ focusElement(first);
462
+ } else {
463
+ const next = getNextFocusable(document.body, {
464
+ anchor: this.#exitSentinel,
465
+ composed: true
466
+ });
467
+ next && focusElement(next);
468
+ }
461
469
  return;
462
470
  }
463
471
  if (current === this.#exitSentinel) {
@@ -467,7 +475,15 @@ var Portal = class {
467
475
  }
468
476
  this.#update();
469
477
  const last = [...this.#focusables].at(-1);
470
- last && focusElement(last);
478
+ if (last) {
479
+ focusElement(last);
480
+ } else {
481
+ const previous = getPreviousFocusable(document.body, {
482
+ anchor: this.#entranceSentinel,
483
+ composed: true
484
+ });
485
+ previous && focusElement(previous);
486
+ }
471
487
  return;
472
488
  }
473
489
  };
@@ -573,7 +589,7 @@ function getActiveElement2() {
573
589
  * Lightweight DOM portal (teleport) utility with fully focus management.
574
590
  * Designed for accessible dialogs, menus, overlays, popovers.
575
591
  *
576
- * @version 1.2.13
592
+ * @version 1.2.14
577
593
  * @author Yusuke Kamiyamane
578
594
  * @license MIT
579
595
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.cts CHANGED
@@ -3,7 +3,7 @@
3
3
  * Lightweight DOM portal (teleport) utility with fully focus management.
4
4
  * Designed for accessible dialogs, menus, overlays, popovers.
5
5
  *
6
- * @version 1.2.13
6
+ * @version 1.2.14
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 DOM portal (teleport) utility with fully focus management.
4
4
  * Designed for accessible dialogs, menus, overlays, popovers.
5
5
  *
6
- * @version 1.2.13
6
+ * @version 1.2.14
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -455,7 +455,15 @@ var Portal = class {
455
455
  }
456
456
  this.#update();
457
457
  const first = [...this.#focusables][0];
458
- first && focusElement(first);
458
+ if (first) {
459
+ focusElement(first);
460
+ } else {
461
+ const next = getNextFocusable(document.body, {
462
+ anchor: this.#exitSentinel,
463
+ composed: true
464
+ });
465
+ next && focusElement(next);
466
+ }
459
467
  return;
460
468
  }
461
469
  if (current === this.#exitSentinel) {
@@ -465,7 +473,15 @@ var Portal = class {
465
473
  }
466
474
  this.#update();
467
475
  const last = [...this.#focusables].at(-1);
468
- last && focusElement(last);
476
+ if (last) {
477
+ focusElement(last);
478
+ } else {
479
+ const previous = getPreviousFocusable(document.body, {
480
+ anchor: this.#entranceSentinel,
481
+ composed: true
482
+ });
483
+ previous && focusElement(previous);
484
+ }
469
485
  return;
470
486
  }
471
487
  };
@@ -571,7 +587,7 @@ function getActiveElement2() {
571
587
  * Lightweight DOM portal (teleport) utility with fully focus management.
572
588
  * Designed for accessible dialogs, menus, overlays, popovers.
573
589
  *
574
- * @version 1.2.13
590
+ * @version 1.2.14
575
591
  * @author Yusuke Kamiyamane
576
592
  * @license MIT
577
593
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/portal",
3
- "version": "1.2.13",
3
+ "version": "1.2.14",
4
4
  "description": "Lightweight DOM portal (teleport) utility with fully focus management",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",