@primer/behaviors 0.0.0-202201891142 → 0.0.0-2022020145740
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/anchored-position.d.ts +15 -0
- package/dist/cjs/anchored-position.js +210 -0
- package/dist/cjs/focus-trap.d.ts +2 -0
- package/dist/cjs/focus-trap.js +111 -0
- package/dist/cjs/focus-zone.d.ts +32 -0
- package/dist/cjs/focus-zone.js +410 -0
- package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- package/dist/cjs/index.js +16 -0
- package/dist/{polyfills → cjs/polyfills}/event-listener-signal.d.ts +0 -0
- package/dist/cjs/polyfills/event-listener-signal.js +44 -0
- package/dist/{scroll-into-view.d.ts → cjs/scroll-into-view.d.ts} +0 -0
- package/dist/cjs/scroll-into-view.js +21 -0
- package/dist/{utils → cjs/utils}/index.d.ts +0 -0
- package/dist/cjs/utils/index.js +15 -0
- package/dist/cjs/utils/iterate-focusable-elements.d.ts +8 -0
- package/dist/cjs/utils/iterate-focusable-elements.js +63 -0
- package/dist/{utils → cjs/utils}/unique-id.d.ts +0 -0
- package/dist/cjs/utils/unique-id.js +8 -0
- package/dist/{utils → cjs/utils}/user-agent.d.ts +0 -0
- package/dist/cjs/utils/user-agent.js +11 -0
- package/dist/esm/anchored-position.d.ts +15 -0
- package/dist/esm/anchored-position.js +206 -0
- package/dist/esm/focus-trap.d.ts +2 -0
- package/dist/esm/focus-trap.js +107 -0
- package/dist/esm/focus-zone.d.ts +32 -0
- package/dist/esm/focus-zone.js +406 -0
- package/{lib-esm → dist/esm}/index.d.ts +0 -0
- package/{lib/index.d.ts → dist/esm/index.js} +0 -0
- package/{lib-esm → dist/esm}/polyfills/event-listener-signal.d.ts +0 -0
- package/dist/esm/polyfills/event-listener-signal.js +40 -0
- package/{lib-esm → dist/esm}/scroll-into-view.d.ts +0 -0
- package/dist/esm/scroll-into-view.js +17 -0
- package/{lib-esm → dist/esm}/utils/index.d.ts +0 -0
- package/{lib/utils/index.d.ts → dist/esm/utils/index.js} +0 -0
- package/dist/esm/utils/iterate-focusable-elements.d.ts +8 -0
- package/dist/esm/utils/iterate-focusable-elements.js +57 -0
- package/{lib-esm → dist/esm}/utils/unique-id.d.ts +0 -0
- package/dist/esm/utils/unique-id.js +4 -0
- package/{lib-esm → dist/esm}/utils/user-agent.d.ts +0 -0
- package/dist/esm/utils/user-agent.js +7 -0
- package/package.json +18 -30
- package/utils/package.json +6 -6
- package/dist/anchored-position.d.ts +0 -89
- package/dist/focus-trap.d.ts +0 -12
- package/dist/focus-zone.d.ts +0 -137
- package/dist/utils/iterate-focusable-elements.d.ts +0 -42
- package/lib/__tests__/anchored-position.test.js +0 -388
- package/lib/__tests__/scroll-into-view.test.js +0 -245
- package/lib/anchored-position.d.ts +0 -89
- package/lib/anchored-position.js +0 -316
- package/lib/focus-trap.d.ts +0 -12
- package/lib/focus-trap.js +0 -179
- package/lib/focus-zone.d.ts +0 -137
- package/lib/focus-zone.js +0 -578
- package/lib/index.js +0 -57
- package/lib/polyfills/event-listener-signal.d.ts +0 -6
- package/lib/polyfills/event-listener-signal.js +0 -64
- package/lib/scroll-into-view.d.ts +0 -7
- package/lib/scroll-into-view.js +0 -42
- package/lib/utils/index.js +0 -44
- package/lib/utils/iterate-focusable-elements.d.ts +0 -42
- package/lib/utils/iterate-focusable-elements.js +0 -113
- package/lib/utils/unique-id.d.ts +0 -1
- package/lib/utils/unique-id.js +0 -12
- package/lib/utils/user-agent.d.ts +0 -1
- package/lib/utils/user-agent.js +0 -15
- package/lib-esm/__tests__/anchored-position.test.js +0 -386
- package/lib-esm/__tests__/scroll-into-view.test.js +0 -243
- package/lib-esm/anchored-position.d.ts +0 -89
- package/lib-esm/anchored-position.js +0 -309
- package/lib-esm/focus-trap.d.ts +0 -12
- package/lib-esm/focus-trap.js +0 -170
- package/lib-esm/focus-zone.d.ts +0 -137
- package/lib-esm/focus-zone.js +0 -559
- package/lib-esm/index.js +0 -4
- package/lib-esm/polyfills/event-listener-signal.js +0 -57
- package/lib-esm/scroll-into-view.js +0 -35
- package/lib-esm/utils/index.js +0 -3
- package/lib-esm/utils/iterate-focusable-elements.d.ts +0 -42
- package/lib-esm/utils/iterate-focusable-elements.js +0 -102
- package/lib-esm/utils/unique-id.js +0 -5
- package/lib-esm/utils/user-agent.js +0 -8
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
const alternateOrders = {
|
|
2
|
+
'outside-top': ['outside-bottom', 'outside-right', 'outside-left', 'outside-bottom'],
|
|
3
|
+
'outside-bottom': ['outside-top', 'outside-right', 'outside-left', 'outside-bottom'],
|
|
4
|
+
'outside-left': ['outside-right', 'outside-bottom', 'outside-top', 'outside-bottom'],
|
|
5
|
+
'outside-right': ['outside-left', 'outside-bottom', 'outside-top', 'outside-bottom']
|
|
6
|
+
};
|
|
7
|
+
export function getAnchoredPosition(floatingElement, anchorElement, settings = {}) {
|
|
8
|
+
const parentElement = getPositionedParent(floatingElement);
|
|
9
|
+
const clippingRect = getClippingRect(parentElement);
|
|
10
|
+
const parentElementStyle = getComputedStyle(parentElement);
|
|
11
|
+
const parentElementRect = parentElement.getBoundingClientRect();
|
|
12
|
+
const [borderTop, borderLeft] = [parentElementStyle.borderTopWidth, parentElementStyle.borderLeftWidth].map(v => parseInt(v, 10) || 0);
|
|
13
|
+
const relativeRect = {
|
|
14
|
+
top: parentElementRect.top + borderTop,
|
|
15
|
+
left: parentElementRect.left + borderLeft
|
|
16
|
+
};
|
|
17
|
+
return pureCalculateAnchoredPosition(clippingRect, relativeRect, floatingElement.getBoundingClientRect(), anchorElement instanceof Element ? anchorElement.getBoundingClientRect() : anchorElement, getDefaultSettings(settings));
|
|
18
|
+
}
|
|
19
|
+
function getPositionedParent(element) {
|
|
20
|
+
let parentNode = element.parentNode;
|
|
21
|
+
while (parentNode !== null) {
|
|
22
|
+
if (parentNode instanceof HTMLElement && getComputedStyle(parentNode).position !== 'static') {
|
|
23
|
+
return parentNode;
|
|
24
|
+
}
|
|
25
|
+
parentNode = parentNode.parentNode;
|
|
26
|
+
}
|
|
27
|
+
return document.body;
|
|
28
|
+
}
|
|
29
|
+
function getClippingRect(element) {
|
|
30
|
+
let parentNode = element;
|
|
31
|
+
while (parentNode !== null) {
|
|
32
|
+
if (parentNode === document.body) {
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
const parentNodeStyle = getComputedStyle(parentNode);
|
|
36
|
+
if (parentNodeStyle.overflow !== 'visible') {
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
parentNode = parentNode.parentNode;
|
|
40
|
+
}
|
|
41
|
+
const clippingNode = parentNode === document.body || !(parentNode instanceof HTMLElement) ? document.body : parentNode;
|
|
42
|
+
const elemRect = clippingNode.getBoundingClientRect();
|
|
43
|
+
const elemStyle = getComputedStyle(clippingNode);
|
|
44
|
+
const [borderTop, borderLeft, borderRight, borderBottom] = [
|
|
45
|
+
elemStyle.borderTopWidth,
|
|
46
|
+
elemStyle.borderLeftWidth,
|
|
47
|
+
elemStyle.borderRightWidth,
|
|
48
|
+
elemStyle.borderBottomWidth
|
|
49
|
+
].map(v => parseInt(v, 10) || 0);
|
|
50
|
+
return {
|
|
51
|
+
top: elemRect.top + borderTop,
|
|
52
|
+
left: elemRect.left + borderLeft,
|
|
53
|
+
width: elemRect.width - borderRight - borderLeft,
|
|
54
|
+
height: Math.max(elemRect.height - borderTop - borderBottom, clippingNode === document.body ? window.innerHeight : -Infinity)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const positionDefaults = {
|
|
58
|
+
side: 'outside-bottom',
|
|
59
|
+
align: 'start',
|
|
60
|
+
anchorOffset: 4,
|
|
61
|
+
alignmentOffset: 4,
|
|
62
|
+
allowOutOfBounds: false
|
|
63
|
+
};
|
|
64
|
+
function getDefaultSettings(settings = {}) {
|
|
65
|
+
var _a, _b, _c, _d, _e;
|
|
66
|
+
const side = (_a = settings.side) !== null && _a !== void 0 ? _a : positionDefaults.side;
|
|
67
|
+
const align = (_b = settings.align) !== null && _b !== void 0 ? _b : positionDefaults.align;
|
|
68
|
+
return {
|
|
69
|
+
side,
|
|
70
|
+
align,
|
|
71
|
+
anchorOffset: (_c = settings.anchorOffset) !== null && _c !== void 0 ? _c : (side === 'inside-center' ? 0 : positionDefaults.anchorOffset),
|
|
72
|
+
alignmentOffset: (_d = settings.alignmentOffset) !== null && _d !== void 0 ? _d : (align !== 'center' && side.startsWith('inside') ? positionDefaults.alignmentOffset : 0),
|
|
73
|
+
allowOutOfBounds: (_e = settings.allowOutOfBounds) !== null && _e !== void 0 ? _e : positionDefaults.allowOutOfBounds
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function pureCalculateAnchoredPosition(viewportRect, relativePosition, floatingRect, anchorRect, { side, align, allowOutOfBounds, anchorOffset, alignmentOffset }) {
|
|
77
|
+
const relativeViewportRect = {
|
|
78
|
+
top: viewportRect.top - relativePosition.top,
|
|
79
|
+
left: viewportRect.left - relativePosition.left,
|
|
80
|
+
width: viewportRect.width,
|
|
81
|
+
height: viewportRect.height
|
|
82
|
+
};
|
|
83
|
+
let pos = calculatePosition(floatingRect, anchorRect, side, align, anchorOffset, alignmentOffset);
|
|
84
|
+
let anchorSide = side;
|
|
85
|
+
pos.top -= relativePosition.top;
|
|
86
|
+
pos.left -= relativePosition.left;
|
|
87
|
+
if (!allowOutOfBounds) {
|
|
88
|
+
const alternateOrder = alternateOrders[side];
|
|
89
|
+
let positionAttempt = 0;
|
|
90
|
+
if (alternateOrder) {
|
|
91
|
+
let prevSide = side;
|
|
92
|
+
while (positionAttempt < alternateOrder.length &&
|
|
93
|
+
shouldRecalculatePosition(prevSide, pos, relativeViewportRect, floatingRect)) {
|
|
94
|
+
const nextSide = alternateOrder[positionAttempt++];
|
|
95
|
+
prevSide = nextSide;
|
|
96
|
+
pos = calculatePosition(floatingRect, anchorRect, nextSide, align, anchorOffset, alignmentOffset);
|
|
97
|
+
pos.top -= relativePosition.top;
|
|
98
|
+
pos.left -= relativePosition.left;
|
|
99
|
+
anchorSide = nextSide;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (pos.top < relativeViewportRect.top) {
|
|
103
|
+
pos.top = relativeViewportRect.top;
|
|
104
|
+
}
|
|
105
|
+
if (pos.left < relativeViewportRect.left) {
|
|
106
|
+
pos.left = relativeViewportRect.left;
|
|
107
|
+
}
|
|
108
|
+
if (pos.left + floatingRect.width > viewportRect.width + relativeViewportRect.left) {
|
|
109
|
+
pos.left = viewportRect.width + relativeViewportRect.left - floatingRect.width;
|
|
110
|
+
}
|
|
111
|
+
if (alternateOrder && positionAttempt < alternateOrder.length) {
|
|
112
|
+
if (pos.top + floatingRect.height > viewportRect.height + relativeViewportRect.top) {
|
|
113
|
+
pos.top = viewportRect.height + relativeViewportRect.top - floatingRect.height;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return Object.assign(Object.assign({}, pos), { anchorSide });
|
|
118
|
+
}
|
|
119
|
+
function calculatePosition(elementDimensions, anchorPosition, side, align, anchorOffset, alignmentOffset) {
|
|
120
|
+
const anchorRight = anchorPosition.left + anchorPosition.width;
|
|
121
|
+
const anchorBottom = anchorPosition.top + anchorPosition.height;
|
|
122
|
+
let top = -1;
|
|
123
|
+
let left = -1;
|
|
124
|
+
if (side === 'outside-top') {
|
|
125
|
+
top = anchorPosition.top - anchorOffset - elementDimensions.height;
|
|
126
|
+
}
|
|
127
|
+
else if (side === 'outside-bottom') {
|
|
128
|
+
top = anchorBottom + anchorOffset;
|
|
129
|
+
}
|
|
130
|
+
else if (side === 'outside-left') {
|
|
131
|
+
left = anchorPosition.left - anchorOffset - elementDimensions.width;
|
|
132
|
+
}
|
|
133
|
+
else if (side === 'outside-right') {
|
|
134
|
+
left = anchorRight + anchorOffset;
|
|
135
|
+
}
|
|
136
|
+
if (side === 'outside-top' || side === 'outside-bottom') {
|
|
137
|
+
if (align === 'start') {
|
|
138
|
+
left = anchorPosition.left + alignmentOffset;
|
|
139
|
+
}
|
|
140
|
+
else if (align === 'center') {
|
|
141
|
+
left = anchorPosition.left - (elementDimensions.width - anchorPosition.width) / 2 + alignmentOffset;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
left = anchorRight - elementDimensions.width - alignmentOffset;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (side === 'outside-left' || side === 'outside-right') {
|
|
148
|
+
if (align === 'start') {
|
|
149
|
+
top = anchorPosition.top + alignmentOffset;
|
|
150
|
+
}
|
|
151
|
+
else if (align === 'center') {
|
|
152
|
+
top = anchorPosition.top - (elementDimensions.height - anchorPosition.height) / 2 + alignmentOffset;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
top = anchorBottom - elementDimensions.height - alignmentOffset;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (side === 'inside-top') {
|
|
159
|
+
top = anchorPosition.top + anchorOffset;
|
|
160
|
+
}
|
|
161
|
+
else if (side === 'inside-bottom') {
|
|
162
|
+
top = anchorBottom - anchorOffset - elementDimensions.height;
|
|
163
|
+
}
|
|
164
|
+
else if (side === 'inside-left') {
|
|
165
|
+
left = anchorPosition.left + anchorOffset;
|
|
166
|
+
}
|
|
167
|
+
else if (side === 'inside-right') {
|
|
168
|
+
left = anchorRight - anchorOffset - elementDimensions.width;
|
|
169
|
+
}
|
|
170
|
+
else if (side === 'inside-center') {
|
|
171
|
+
left = (anchorRight + anchorPosition.left) / 2 - elementDimensions.width / 2 + anchorOffset;
|
|
172
|
+
}
|
|
173
|
+
if (side === 'inside-top' || side === 'inside-bottom') {
|
|
174
|
+
if (align === 'start') {
|
|
175
|
+
left = anchorPosition.left + alignmentOffset;
|
|
176
|
+
}
|
|
177
|
+
else if (align === 'center') {
|
|
178
|
+
left = anchorPosition.left - (elementDimensions.width - anchorPosition.width) / 2 + alignmentOffset;
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
left = anchorRight - elementDimensions.width - alignmentOffset;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
else if (side === 'inside-left' || side === 'inside-right' || side === 'inside-center') {
|
|
185
|
+
if (align === 'start') {
|
|
186
|
+
top = anchorPosition.top + alignmentOffset;
|
|
187
|
+
}
|
|
188
|
+
else if (align === 'center') {
|
|
189
|
+
top = anchorPosition.top - (elementDimensions.height - anchorPosition.height) / 2 + alignmentOffset;
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
top = anchorBottom - elementDimensions.height - alignmentOffset;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return { top, left };
|
|
196
|
+
}
|
|
197
|
+
function shouldRecalculatePosition(side, currentPos, containerDimensions, elementDimensions) {
|
|
198
|
+
if (side === 'outside-top' || side === 'outside-bottom') {
|
|
199
|
+
return (currentPos.top < containerDimensions.top ||
|
|
200
|
+
currentPos.top + elementDimensions.height > containerDimensions.height + containerDimensions.top);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
return (currentPos.left < containerDimensions.left ||
|
|
204
|
+
currentPos.left + elementDimensions.width > containerDimensions.width + containerDimensions.left);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { isTabbable, iterateFocusableElements } from './utils/iterate-focusable-elements.js';
|
|
2
|
+
import { polyfill as eventListenerSignalPolyfill } from './polyfills/event-listener-signal.js';
|
|
3
|
+
eventListenerSignalPolyfill();
|
|
4
|
+
const suspendedTrapStack = [];
|
|
5
|
+
let activeTrap = undefined;
|
|
6
|
+
function tryReactivate() {
|
|
7
|
+
const trapToReactivate = suspendedTrapStack.pop();
|
|
8
|
+
if (trapToReactivate) {
|
|
9
|
+
focusTrap(trapToReactivate.container, trapToReactivate.initialFocus, trapToReactivate.originalSignal);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function followSignal(signal) {
|
|
13
|
+
const controller = new AbortController();
|
|
14
|
+
signal.addEventListener('abort', () => {
|
|
15
|
+
controller.abort();
|
|
16
|
+
});
|
|
17
|
+
return controller;
|
|
18
|
+
}
|
|
19
|
+
function getFocusableChild(container, lastChild = false) {
|
|
20
|
+
return iterateFocusableElements(container, { reverse: lastChild, strict: true, onlyTabbable: true }).next().value;
|
|
21
|
+
}
|
|
22
|
+
export function focusTrap(container, initialFocus, abortSignal) {
|
|
23
|
+
const controller = new AbortController();
|
|
24
|
+
const signal = abortSignal !== null && abortSignal !== void 0 ? abortSignal : controller.signal;
|
|
25
|
+
container.setAttribute('data-focus-trap', 'active');
|
|
26
|
+
let lastFocusedChild = undefined;
|
|
27
|
+
function ensureTrapZoneHasFocus(focusedElement) {
|
|
28
|
+
if (focusedElement instanceof HTMLElement && document.contains(container)) {
|
|
29
|
+
if (container.contains(focusedElement)) {
|
|
30
|
+
lastFocusedChild = focusedElement;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
if (lastFocusedChild && isTabbable(lastFocusedChild) && container.contains(lastFocusedChild)) {
|
|
35
|
+
lastFocusedChild.focus();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
else if (initialFocus && container.contains(initialFocus)) {
|
|
39
|
+
initialFocus.focus();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const containerNeedsTemporaryTabIndex = container.getAttribute('tabindex') === null;
|
|
44
|
+
if (containerNeedsTemporaryTabIndex) {
|
|
45
|
+
container.setAttribute('tabindex', '-1');
|
|
46
|
+
}
|
|
47
|
+
container.focus();
|
|
48
|
+
if (containerNeedsTemporaryTabIndex) {
|
|
49
|
+
container.addEventListener('blur', () => container.removeAttribute('tabindex'), { once: true });
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const wrappingController = followSignal(signal);
|
|
57
|
+
container.addEventListener('keydown', event => {
|
|
58
|
+
if (event.key !== 'Tab' || event.defaultPrevented) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const { target } = event;
|
|
62
|
+
const firstFocusableChild = getFocusableChild(container);
|
|
63
|
+
const lastFocusableChild = getFocusableChild(container, true);
|
|
64
|
+
if (target === firstFocusableChild && event.shiftKey) {
|
|
65
|
+
event.preventDefault();
|
|
66
|
+
lastFocusableChild === null || lastFocusableChild === void 0 ? void 0 : lastFocusableChild.focus();
|
|
67
|
+
}
|
|
68
|
+
else if (target === lastFocusableChild && !event.shiftKey) {
|
|
69
|
+
event.preventDefault();
|
|
70
|
+
firstFocusableChild === null || firstFocusableChild === void 0 ? void 0 : firstFocusableChild.focus();
|
|
71
|
+
}
|
|
72
|
+
}, { signal: wrappingController.signal });
|
|
73
|
+
if (activeTrap) {
|
|
74
|
+
const suspendedTrap = activeTrap;
|
|
75
|
+
activeTrap.container.setAttribute('data-focus-trap', 'suspended');
|
|
76
|
+
activeTrap.controller.abort();
|
|
77
|
+
suspendedTrapStack.push(suspendedTrap);
|
|
78
|
+
}
|
|
79
|
+
wrappingController.signal.addEventListener('abort', () => {
|
|
80
|
+
activeTrap = undefined;
|
|
81
|
+
});
|
|
82
|
+
signal.addEventListener('abort', () => {
|
|
83
|
+
container.removeAttribute('data-focus-trap');
|
|
84
|
+
const suspendedTrapIndex = suspendedTrapStack.findIndex(t => t.container === container);
|
|
85
|
+
if (suspendedTrapIndex >= 0) {
|
|
86
|
+
suspendedTrapStack.splice(suspendedTrapIndex, 1);
|
|
87
|
+
}
|
|
88
|
+
tryReactivate();
|
|
89
|
+
});
|
|
90
|
+
document.addEventListener('focus', event => {
|
|
91
|
+
ensureTrapZoneHasFocus(event.target);
|
|
92
|
+
}, { signal: wrappingController.signal, capture: true });
|
|
93
|
+
ensureTrapZoneHasFocus(document.activeElement);
|
|
94
|
+
activeTrap = {
|
|
95
|
+
container,
|
|
96
|
+
controller: wrappingController,
|
|
97
|
+
initialFocus,
|
|
98
|
+
originalSignal: signal
|
|
99
|
+
};
|
|
100
|
+
const suspendedTrapIndex = suspendedTrapStack.findIndex(t => t.container === container);
|
|
101
|
+
if (suspendedTrapIndex >= 0) {
|
|
102
|
+
suspendedTrapStack.splice(suspendedTrapIndex, 1);
|
|
103
|
+
}
|
|
104
|
+
if (!abortSignal) {
|
|
105
|
+
return controller;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare type Direction = 'previous' | 'next' | 'start' | 'end';
|
|
2
|
+
export declare type FocusMovementKeys = 'ArrowLeft' | 'ArrowDown' | 'ArrowUp' | 'ArrowRight' | 'h' | 'j' | 'k' | 'l' | 'a' | 's' | 'w' | 'd' | 'Tab' | 'Home' | 'End' | 'PageUp' | 'PageDown';
|
|
3
|
+
export declare enum FocusKeys {
|
|
4
|
+
ArrowHorizontal = 1,
|
|
5
|
+
ArrowVertical = 2,
|
|
6
|
+
JK = 4,
|
|
7
|
+
HL = 8,
|
|
8
|
+
HomeAndEnd = 16,
|
|
9
|
+
PageUpDown = 256,
|
|
10
|
+
WS = 32,
|
|
11
|
+
AD = 64,
|
|
12
|
+
Tab = 128,
|
|
13
|
+
ArrowAll = 3,
|
|
14
|
+
HJKL = 12,
|
|
15
|
+
WASD = 96,
|
|
16
|
+
All = 511
|
|
17
|
+
}
|
|
18
|
+
export interface FocusZoneSettings {
|
|
19
|
+
focusOutBehavior?: 'stop' | 'wrap';
|
|
20
|
+
getNextFocusable?: (direction: Direction, from: Element | undefined, event: KeyboardEvent) => HTMLElement | undefined;
|
|
21
|
+
focusableElementFilter?: (element: HTMLElement) => boolean;
|
|
22
|
+
bindKeys?: FocusKeys;
|
|
23
|
+
abortSignal?: AbortSignal;
|
|
24
|
+
activeDescendantControl?: HTMLElement;
|
|
25
|
+
onActiveDescendantChanged?: (newActiveDescendant: HTMLElement | undefined, previousActiveDescendant: HTMLElement | undefined, directlyActivated: boolean) => void;
|
|
26
|
+
focusInStrategy?: 'first' | 'closest' | 'previous' | ((previousFocusedElement: Element) => HTMLElement | undefined);
|
|
27
|
+
}
|
|
28
|
+
export declare const isActiveDescendantAttribute = "data-is-active-descendant";
|
|
29
|
+
export declare const activeDescendantActivatedDirectly = "activated-directly";
|
|
30
|
+
export declare const activeDescendantActivatedIndirectly = "activated-indirectly";
|
|
31
|
+
export declare const hasActiveDescendantAttribute = "data-has-active-descendant";
|
|
32
|
+
export declare function focusZone(container: HTMLElement, settings?: FocusZoneSettings): AbortController;
|