@primer/behaviors 0.0.0-20241107171114 → 0.0.0-20250107214134

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.
@@ -62,11 +62,8 @@ function focusTrap(container, initialFocus, abortSignal) {
62
62
  const firstFocusableChild = iterateFocusableElements.getFocusableChild(container);
63
63
  firstFocusableChild === null || firstFocusableChild === void 0 ? void 0 : firstFocusableChild.focus();
64
64
  };
65
- const existingSentinels = Array.from(container.children).filter(e => e.classList.contains('sentinel') && e.tagName === 'SPAN');
66
- if (!existingSentinels.length) {
67
- container.prepend(sentinelStart);
68
- container.append(sentinelEnd);
69
- }
65
+ container.prepend(sentinelStart);
66
+ container.append(sentinelEnd);
70
67
  const observer = observeFocusTrap(container, [sentinelStart, sentinelEnd]);
71
68
  let lastFocusedChild = undefined;
72
69
  function ensureTrapZoneHasFocus(focusedElement) {
@@ -76,22 +73,34 @@ function focusTrap(container, initialFocus, abortSignal) {
76
73
  return;
77
74
  }
78
75
  else {
76
+ const focusDelay = suspendedTrapStack.length > 0 ? 50 : undefined;
79
77
  if (lastFocusedChild && iterateFocusableElements.isTabbable(lastFocusedChild) && container.contains(lastFocusedChild)) {
80
- lastFocusedChild.focus();
78
+ handleFocus(lastFocusedChild, focusDelay);
81
79
  return;
82
80
  }
83
81
  else if (initialFocus && container.contains(initialFocus)) {
84
- initialFocus.focus();
82
+ handleFocus(initialFocus, focusDelay);
85
83
  return;
86
84
  }
87
85
  else {
88
86
  const firstFocusableChild = iterateFocusableElements.getFocusableChild(container);
89
- firstFocusableChild === null || firstFocusableChild === void 0 ? void 0 : firstFocusableChild.focus();
87
+ handleFocus(firstFocusableChild, focusDelay);
90
88
  return;
91
89
  }
92
90
  }
93
91
  }
94
92
  }
93
+ function handleFocus(focusTarget, delay) {
94
+ if (!focusTarget)
95
+ return;
96
+ if (delay) {
97
+ setTimeout(() => {
98
+ focusTarget.focus();
99
+ }, delay);
100
+ return;
101
+ }
102
+ focusTarget.focus();
103
+ }
95
104
  const wrappingController = followSignal(signal);
96
105
  if (activeTrap) {
97
106
  const suspendedTrap = activeTrap;
@@ -60,11 +60,8 @@ function focusTrap(container, initialFocus, abortSignal) {
60
60
  const firstFocusableChild = getFocusableChild(container);
61
61
  firstFocusableChild === null || firstFocusableChild === void 0 ? void 0 : firstFocusableChild.focus();
62
62
  };
63
- const existingSentinels = Array.from(container.children).filter(e => e.classList.contains('sentinel') && e.tagName === 'SPAN');
64
- if (!existingSentinels.length) {
65
- container.prepend(sentinelStart);
66
- container.append(sentinelEnd);
67
- }
63
+ container.prepend(sentinelStart);
64
+ container.append(sentinelEnd);
68
65
  const observer = observeFocusTrap(container, [sentinelStart, sentinelEnd]);
69
66
  let lastFocusedChild = undefined;
70
67
  function ensureTrapZoneHasFocus(focusedElement) {
@@ -74,22 +71,34 @@ function focusTrap(container, initialFocus, abortSignal) {
74
71
  return;
75
72
  }
76
73
  else {
74
+ const focusDelay = suspendedTrapStack.length > 0 ? 50 : undefined;
77
75
  if (lastFocusedChild && isTabbable(lastFocusedChild) && container.contains(lastFocusedChild)) {
78
- lastFocusedChild.focus();
76
+ handleFocus(lastFocusedChild, focusDelay);
79
77
  return;
80
78
  }
81
79
  else if (initialFocus && container.contains(initialFocus)) {
82
- initialFocus.focus();
80
+ handleFocus(initialFocus, focusDelay);
83
81
  return;
84
82
  }
85
83
  else {
86
84
  const firstFocusableChild = getFocusableChild(container);
87
- firstFocusableChild === null || firstFocusableChild === void 0 ? void 0 : firstFocusableChild.focus();
85
+ handleFocus(firstFocusableChild, focusDelay);
88
86
  return;
89
87
  }
90
88
  }
91
89
  }
92
90
  }
91
+ function handleFocus(focusTarget, delay) {
92
+ if (!focusTarget)
93
+ return;
94
+ if (delay) {
95
+ setTimeout(() => {
96
+ focusTarget.focus();
97
+ }, delay);
98
+ return;
99
+ }
100
+ focusTarget.focus();
101
+ }
93
102
  const wrappingController = followSignal(signal);
94
103
  if (activeTrap) {
95
104
  const suspendedTrap = activeTrap;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/behaviors",
3
- "version": "0.0.0-20241107171114",
3
+ "version": "0.0.0-20250107214134",
4
4
  "description": "Shared behaviors for JavaScript components",
5
5
  "type": "commonjs",
6
6
  "main": "dist/cjs/index.js",
@@ -69,7 +69,7 @@
69
69
  }
70
70
  ],
71
71
  "devDependencies": {
72
- "@arethetypeswrong/cli": "^0.16.2",
72
+ "@arethetypeswrong/cli": "^0.17.0",
73
73
  "@changesets/changelog-github": "^0.5.0",
74
74
  "@changesets/cli": "^2.18.1",
75
75
  "@github/prettier-config": "^0.0.6",
@@ -80,7 +80,7 @@
80
80
  "@testing-library/user-event": "^14.5.1",
81
81
  "@types/jest": "^29.5.11",
82
82
  "@types/node": "^22.0.0",
83
- "@types/react": "^18.2.23",
83
+ "@types/react": "^19.0.1",
84
84
  "esbuild": "^0.24.0",
85
85
  "esbuild-jest": "^0.5.0",
86
86
  "eslint": "^8.50.0",
@@ -89,8 +89,8 @@
89
89
  "jest": "^29.7.0",
90
90
  "jest-environment-jsdom": "^29.7.0",
91
91
  "prettier": "^3.0.3",
92
- "react": "^18.2.0",
93
- "react-dom": "^18.2.0",
92
+ "react": "^19.0.0",
93
+ "react-dom": "^19.0.0",
94
94
  "rimraf": "^6.0.1",
95
95
  "rollup": "^4.18.0",
96
96
  "size-limit": "^11.1.4",