@y14e/portal 1.2.9 → 1.2.11

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.9';
13
+ import { createPortal } from '@y14e/portal@1.2.11';
14
14
 
15
15
  // CDNs
16
- import { createPortal } from 'https://esm.sh/@y14e/portal@1.2.9';
16
+ import { createPortal } from 'https://esm.sh/@y14e/portal@1.2.11';
17
17
  // or
18
- import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@1.2.9/+esm';
18
+ import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@1.2.11/+esm';
19
19
  // or
20
- import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@1.2.9';
20
+ import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@1.2.11';
21
21
  ```
22
22
 
23
23
  ## 📦 APIs
package/dist/index.cjs CHANGED
@@ -452,7 +452,15 @@ var Portal = class {
452
452
  }
453
453
  this.#update();
454
454
  const first = [...this.#focusables][0];
455
- first && focusElement(first);
455
+ if (first) {
456
+ focusElement(first);
457
+ } else {
458
+ const next = getNextFocusable(document.body, {
459
+ anchor: this.#exitSentinel,
460
+ composed: true
461
+ });
462
+ next && focusElement(next);
463
+ }
456
464
  return;
457
465
  }
458
466
  if (current === this.#exitSentinel) {
@@ -462,7 +470,16 @@ var Portal = class {
462
470
  }
463
471
  this.#update();
464
472
  const last = [...this.#focusables].at(-1);
465
- last && focusElement(last);
473
+ if (last) {
474
+ focusElement(last);
475
+ } else {
476
+ const previous = getPreviousFocusable(document.body, {
477
+ anchor: this.#entranceSentinel,
478
+ composed: true
479
+ });
480
+ previous && focusElement(previous);
481
+ }
482
+ return;
466
483
  }
467
484
  };
468
485
  #onKeyDown = (event) => {
@@ -566,7 +583,7 @@ function getActiveElement2() {
566
583
  * Lightweight DOM portal (teleport) utility with fully focus management.
567
584
  * Designed for accessible dialogs, menus, overlays, popovers.
568
585
  *
569
- * @version 1.2.9
586
+ * @version 1.2.11
570
587
  * @author Yusuke Kamiyamane
571
588
  * @license MIT
572
589
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -578,7 +595,7 @@ function getActiveElement2() {
578
595
  (**
579
596
  * Attributes Utils
580
597
  *
581
- * @version 1.1.0
598
+ * @version 1.1.1
582
599
  * @author Yusuke Kamiyamane
583
600
  * @license MIT
584
601
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -591,7 +608,7 @@ power-focusable/dist/index.js:
591
608
  * High-precision focus management utility with full composed tree support.
592
609
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
593
610
  *
594
- * @version 4.3.1
611
+ * @version 4.3.2
595
612
  * @author Yusuke Kamiyamane
596
613
  * @license MIT
597
614
  * @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.9
6
+ * @version 1.2.11
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.9
6
+ * @version 1.2.11
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -450,7 +450,15 @@ var Portal = class {
450
450
  }
451
451
  this.#update();
452
452
  const first = [...this.#focusables][0];
453
- first && focusElement(first);
453
+ if (first) {
454
+ focusElement(first);
455
+ } else {
456
+ const next = getNextFocusable(document.body, {
457
+ anchor: this.#exitSentinel,
458
+ composed: true
459
+ });
460
+ next && focusElement(next);
461
+ }
454
462
  return;
455
463
  }
456
464
  if (current === this.#exitSentinel) {
@@ -460,7 +468,16 @@ var Portal = class {
460
468
  }
461
469
  this.#update();
462
470
  const last = [...this.#focusables].at(-1);
463
- last && focusElement(last);
471
+ if (last) {
472
+ focusElement(last);
473
+ } else {
474
+ const previous = getPreviousFocusable(document.body, {
475
+ anchor: this.#entranceSentinel,
476
+ composed: true
477
+ });
478
+ previous && focusElement(previous);
479
+ }
480
+ return;
464
481
  }
465
482
  };
466
483
  #onKeyDown = (event) => {
@@ -564,7 +581,7 @@ function getActiveElement2() {
564
581
  * Lightweight DOM portal (teleport) utility with fully focus management.
565
582
  * Designed for accessible dialogs, menus, overlays, popovers.
566
583
  *
567
- * @version 1.2.9
584
+ * @version 1.2.11
568
585
  * @author Yusuke Kamiyamane
569
586
  * @license MIT
570
587
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -576,7 +593,7 @@ function getActiveElement2() {
576
593
  (**
577
594
  * Attributes Utils
578
595
  *
579
- * @version 1.1.0
596
+ * @version 1.1.1
580
597
  * @author Yusuke Kamiyamane
581
598
  * @license MIT
582
599
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -589,7 +606,7 @@ power-focusable/dist/index.js:
589
606
  * High-precision focus management utility with full composed tree support.
590
607
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
591
608
  *
592
- * @version 4.3.1
609
+ * @version 4.3.2
593
610
  * @author Yusuke Kamiyamane
594
611
  * @license MIT
595
612
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/portal",
3
- "version": "1.2.9",
3
+ "version": "1.2.11",
4
4
  "description": "Lightweight DOM portal (teleport) utility with fully focus management",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -47,9 +47,9 @@
47
47
  },
48
48
  "homepage": "https://github.com/y14e/portal#readme",
49
49
  "devDependencies": {
50
- "@y14e/attributes-utils": "^1.1.0",
50
+ "@y14e/attributes-utils": "^1.1.1",
51
51
  "bun-types": "latest",
52
- "power-focusable": "^4.3.1",
52
+ "power-focusable": "^4.3.2",
53
53
  "tsup": "^8.0.0",
54
54
  "typescript": "^5.6.0"
55
55
  },