@primer/behaviors 0.0.0-20241210162445 → 0.0.0-20250107215005
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/dist/cjs/focus-trap.js +17 -8
- package/dist/esm/focus-trap.mjs +17 -8
- package/package.json +1 -1
package/dist/cjs/focus-trap.js
CHANGED
|
@@ -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
|
-
|
|
66
|
-
|
|
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
|
|
78
|
+
handleFocus(lastFocusedChild, focusDelay);
|
|
81
79
|
return;
|
|
82
80
|
}
|
|
83
81
|
else if (initialFocus && container.contains(initialFocus)) {
|
|
84
|
-
initialFocus
|
|
82
|
+
handleFocus(initialFocus, focusDelay);
|
|
85
83
|
return;
|
|
86
84
|
}
|
|
87
85
|
else {
|
|
88
86
|
const firstFocusableChild = iterateFocusableElements.getFocusableChild(container);
|
|
89
|
-
firstFocusableChild
|
|
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;
|
package/dist/esm/focus-trap.mjs
CHANGED
|
@@ -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
|
-
|
|
64
|
-
|
|
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
|
|
76
|
+
handleFocus(lastFocusedChild, focusDelay);
|
|
79
77
|
return;
|
|
80
78
|
}
|
|
81
79
|
else if (initialFocus && container.contains(initialFocus)) {
|
|
82
|
-
initialFocus
|
|
80
|
+
handleFocus(initialFocus, focusDelay);
|
|
83
81
|
return;
|
|
84
82
|
}
|
|
85
83
|
else {
|
|
86
84
|
const firstFocusableChild = getFocusableChild(container);
|
|
87
|
-
firstFocusableChild
|
|
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;
|