@primer/behaviors 0.0.0-20251215033828 → 0.0.0-20251215034201
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 +22 -20
- package/dist/esm/focus-trap.mjs +22 -20
- package/package.json +1 -1
package/dist/cjs/focus-trap.js
CHANGED
|
@@ -6,6 +6,16 @@ var eventListenerSignal = require('./polyfills/event-listener-signal.js');
|
|
|
6
6
|
eventListenerSignal.polyfill();
|
|
7
7
|
const suspendedTrapStack = [];
|
|
8
8
|
let activeTrap = undefined;
|
|
9
|
+
const SR_ONLY_STYLES = 'position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0';
|
|
10
|
+
function createSentinel({ onFocus }) {
|
|
11
|
+
const sentinel = document.createElement('span');
|
|
12
|
+
sentinel.setAttribute('class', 'sentinel');
|
|
13
|
+
sentinel.setAttribute('tabindex', '0');
|
|
14
|
+
sentinel.setAttribute('aria-hidden', 'true');
|
|
15
|
+
sentinel.style.cssText = SR_ONLY_STYLES;
|
|
16
|
+
sentinel.onfocus = onFocus;
|
|
17
|
+
return sentinel;
|
|
18
|
+
}
|
|
9
19
|
function tryReactivate() {
|
|
10
20
|
const trapToReactivate = suspendedTrapStack.pop();
|
|
11
21
|
if (trapToReactivate) {
|
|
@@ -47,26 +57,18 @@ function focusTrap(container, initialFocus, abortSignal) {
|
|
|
47
57
|
const controller = new AbortController();
|
|
48
58
|
const signal = abortSignal !== null && abortSignal !== void 0 ? abortSignal : controller.signal;
|
|
49
59
|
container.setAttribute('data-focus-trap', 'active');
|
|
50
|
-
const sentinelStart =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
sentinelEnd.setAttribute('tabindex', '0');
|
|
63
|
-
sentinelEnd.setAttribute('aria-hidden', 'true');
|
|
64
|
-
sentinelEnd.style.cssText =
|
|
65
|
-
'position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0';
|
|
66
|
-
sentinelEnd.onfocus = () => {
|
|
67
|
-
const firstFocusableChild = iterateFocusableElements.getFocusableChild(container);
|
|
68
|
-
firstFocusableChild === null || firstFocusableChild === void 0 ? void 0 : firstFocusableChild.focus();
|
|
69
|
-
};
|
|
60
|
+
const sentinelStart = createSentinel({
|
|
61
|
+
onFocus: () => {
|
|
62
|
+
const lastFocusableChild = iterateFocusableElements.getFocusableChild(container, true);
|
|
63
|
+
lastFocusableChild === null || lastFocusableChild === void 0 ? void 0 : lastFocusableChild.focus();
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
const sentinelEnd = createSentinel({
|
|
67
|
+
onFocus: () => {
|
|
68
|
+
const firstFocusableChild = iterateFocusableElements.getFocusableChild(container);
|
|
69
|
+
firstFocusableChild === null || firstFocusableChild === void 0 ? void 0 : firstFocusableChild.focus();
|
|
70
|
+
},
|
|
71
|
+
});
|
|
70
72
|
const hasExistingSentinels = container.querySelector(':scope > span.sentinel') !== null;
|
|
71
73
|
if (!hasExistingSentinels) {
|
|
72
74
|
container.prepend(sentinelStart);
|
package/dist/esm/focus-trap.mjs
CHANGED
|
@@ -4,6 +4,16 @@ import { polyfill } from './polyfills/event-listener-signal.mjs';
|
|
|
4
4
|
polyfill();
|
|
5
5
|
const suspendedTrapStack = [];
|
|
6
6
|
let activeTrap = undefined;
|
|
7
|
+
const SR_ONLY_STYLES = 'position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0';
|
|
8
|
+
function createSentinel({ onFocus }) {
|
|
9
|
+
const sentinel = document.createElement('span');
|
|
10
|
+
sentinel.setAttribute('class', 'sentinel');
|
|
11
|
+
sentinel.setAttribute('tabindex', '0');
|
|
12
|
+
sentinel.setAttribute('aria-hidden', 'true');
|
|
13
|
+
sentinel.style.cssText = SR_ONLY_STYLES;
|
|
14
|
+
sentinel.onfocus = onFocus;
|
|
15
|
+
return sentinel;
|
|
16
|
+
}
|
|
7
17
|
function tryReactivate() {
|
|
8
18
|
const trapToReactivate = suspendedTrapStack.pop();
|
|
9
19
|
if (trapToReactivate) {
|
|
@@ -45,26 +55,18 @@ function focusTrap(container, initialFocus, abortSignal) {
|
|
|
45
55
|
const controller = new AbortController();
|
|
46
56
|
const signal = abortSignal !== null && abortSignal !== void 0 ? abortSignal : controller.signal;
|
|
47
57
|
container.setAttribute('data-focus-trap', 'active');
|
|
48
|
-
const sentinelStart =
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
sentinelEnd.setAttribute('tabindex', '0');
|
|
61
|
-
sentinelEnd.setAttribute('aria-hidden', 'true');
|
|
62
|
-
sentinelEnd.style.cssText =
|
|
63
|
-
'position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0';
|
|
64
|
-
sentinelEnd.onfocus = () => {
|
|
65
|
-
const firstFocusableChild = getFocusableChild(container);
|
|
66
|
-
firstFocusableChild === null || firstFocusableChild === void 0 ? void 0 : firstFocusableChild.focus();
|
|
67
|
-
};
|
|
58
|
+
const sentinelStart = createSentinel({
|
|
59
|
+
onFocus: () => {
|
|
60
|
+
const lastFocusableChild = getFocusableChild(container, true);
|
|
61
|
+
lastFocusableChild === null || lastFocusableChild === void 0 ? void 0 : lastFocusableChild.focus();
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
const sentinelEnd = createSentinel({
|
|
65
|
+
onFocus: () => {
|
|
66
|
+
const firstFocusableChild = getFocusableChild(container);
|
|
67
|
+
firstFocusableChild === null || firstFocusableChild === void 0 ? void 0 : firstFocusableChild.focus();
|
|
68
|
+
},
|
|
69
|
+
});
|
|
68
70
|
const hasExistingSentinels = container.querySelector(':scope > span.sentinel') !== null;
|
|
69
71
|
if (!hasExistingSentinels) {
|
|
70
72
|
container.prepend(sentinelStart);
|