forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfocus-trap+7.5.4.patch
150 lines (141 loc) · 6.88 KB
/
focus-trap+7.5.4.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
diff --git a/node_modules/focus-trap/dist/focus-trap.esm.js b/node_modules/focus-trap/dist/focus-trap.esm.js
index 10d56db..975151c 100644
--- a/node_modules/focus-trap/dist/focus-trap.esm.js
+++ b/node_modules/focus-trap/dist/focus-trap.esm.js
@@ -71,12 +71,12 @@ var activeFocusTraps = {
trapStack.push(trap);
}
},
- deactivateTrap: function deactivateTrap(trapStack, trap) {
+ deactivateTrap: function deactivateTrap(trapStack, trap, unpauseOnDeactivate) {
var trapIndex = trapStack.indexOf(trap);
if (trapIndex !== -1) {
trapStack.splice(trapIndex, 1);
}
- if (trapStack.length > 0) {
+ if (trapStack.length > 0 && unpauseOnDeactivate) {
trapStack[trapStack.length - 1].unpause();
}
}
@@ -100,8 +100,8 @@ var isKeyForward = function isKeyForward(e) {
var isKeyBackward = function isKeyBackward(e) {
return isTabEvent(e) && e.shiftKey;
};
-var delay = function delay(fn) {
- return setTimeout(fn, 0);
+var delay = function delay(fn, delayTime = 0) {
+ return setTimeout(() => setTimeout(fn, delayTime), 0);
};
// Array.find/findIndex() are not supported on IE; this replicates enough
@@ -153,6 +153,7 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
var doc = (userOptions === null || userOptions === void 0 ? void 0 : userOptions.document) || document;
var trapStack = (userOptions === null || userOptions === void 0 ? void 0 : userOptions.trapStack) || internalTrapStack;
var config = _objectSpread2({
+ unpauseOnDeactivate: true,
returnFocusOnDeactivate: true,
escapeDeactivates: true,
delayInitialFocus: true,
@@ -283,7 +284,7 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
return node;
};
var getInitialFocusNode = function getInitialFocusNode() {
- var node = getNodeForOption('initialFocus');
+ var node = getNodeForOption('initialFocus', state.containers);
// false explicitly indicates we want no initialFocus at all
if (node === false) {
@@ -744,7 +745,7 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
// that caused the focus trap activation.
state.delayInitialFocusTimer = config.delayInitialFocus ? delay(function () {
tryFocus(getInitialFocusNode());
- }) : tryFocus(getInitialFocusNode());
+ }, typeof config.delayInitialFocus === 'number' ? config.delayInitialFocus : undefined) : tryFocus(getInitialFocusNode());
doc.addEventListener('focusin', checkFocusIn, true);
doc.addEventListener('mousedown', checkPointerDown, {
capture: true,
@@ -868,7 +869,7 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
state.active = false;
state.paused = false;
updateObservedNodes();
- activeFocusTraps.deactivateTrap(trapStack, trap);
+ activeFocusTraps.deactivateTrap(trapStack, trap, config.unpauseOnDeactivate);
var onDeactivate = getOption(options, 'onDeactivate');
var onPostDeactivate = getOption(options, 'onPostDeactivate');
var checkCanReturnFocus = getOption(options, 'checkCanReturnFocus');
@@ -880,7 +881,7 @@ var createFocusTrap = function createFocusTrap(elements, userOptions) {
tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation));
}
onPostDeactivate === null || onPostDeactivate === void 0 || onPostDeactivate();
- });
+ }, typeof config.delayInitialFocus === 'number' ? config.delayInitialFocus : undefined);
};
if (returnFocus && checkCanReturnFocus) {
checkCanReturnFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation)).then(finishDeactivation, finishDeactivation);
diff --git a/node_modules/focus-trap/index.d.ts b/node_modules/focus-trap/index.d.ts
index 400db1b..78b38d9 100644
--- a/node_modules/focus-trap/index.d.ts
+++ b/node_modules/focus-trap/index.d.ts
@@ -16,7 +16,7 @@ declare module 'focus-trap' {
* `document.querySelector()` to find the DOM node), `false` to explicitly indicate
* an opt-out, or a function that returns a DOM node or `false`.
*/
- export type FocusTargetOrFalse = FocusTargetValueOrFalse | (() => FocusTargetValueOrFalse);
+ export type FocusTargetOrFalse = FocusTargetValueOrFalse | ((containers?: HTMLElement[]) => FocusTargetValueOrFalse | undefined);
type MouseEventToBoolean = (event: MouseEvent | TouchEvent) => boolean;
type KeyboardEventToBoolean = (event: KeyboardEvent) => boolean;
@@ -135,6 +135,11 @@ declare module 'focus-trap' {
* in the trap.
*/
fallbackFocus?: FocusTarget;
+ /**
+ * By default, the previous focus trap on the stack will be unpaused
+ * when the current active trap is deactivated.
+ */
+ unpauseOnDeactivate?: boolean;
/**
* Default: `true`. If `false`, when the trap is deactivated,
* focus will *not* return to the element that had focus before activation.
@@ -185,7 +190,7 @@ declare module 'focus-trap' {
* This prevents elements within the focusable element from capturing
* the event that triggered the focus trap activation.
*/
- delayInitialFocus?: boolean;
+ delayInitialFocus?: boolean | number;
/**
* Default: `window.document`. Document where the focus trap will be active.
* This allows to use FocusTrap in an iFrame context.
diff --git a/node_modules/focus-trap/index.js b/node_modules/focus-trap/index.js
index de8e46a..bfc8b63 100644
--- a/node_modules/focus-trap/index.js
+++ b/node_modules/focus-trap/index.js
@@ -63,8 +63,8 @@ const isKeyBackward = function (e) {
return isTabEvent(e) && e.shiftKey;
};
-const delay = function (fn) {
- return setTimeout(fn, 0);
+const delay = function (fn, delayTime = 0) {
+ return setTimeout(() => setTimeout(fn, delayTime), 0);
};
// Array.find/findIndex() are not supported on IE; this replicates enough
@@ -267,7 +267,7 @@ const createFocusTrap = function (elements, userOptions) {
};
const getInitialFocusNode = function () {
- let node = getNodeForOption('initialFocus');
+ let node = getNodeForOption('initialFocus', state.containers);
// false explicitly indicates we want no initialFocus at all
if (node === false) {
@@ -817,7 +817,7 @@ const createFocusTrap = function (elements, userOptions) {
state.delayInitialFocusTimer = config.delayInitialFocus
? delay(function () {
tryFocus(getInitialFocusNode());
- })
+ }, typeof config.delayInitialFocus === 'number' ? config.delayInitialFocus : undefined)
: tryFocus(getInitialFocusNode());
doc.addEventListener('focusin', checkFocusIn, true);
@@ -989,7 +989,7 @@ const createFocusTrap = function (elements, userOptions) {
tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation));
}
onPostDeactivate?.();
- });
+ }, typeof config.delayInitialFocus === 'number' ? config.delayInitialFocus : undefined);
};
if (returnFocus && checkCanReturnFocus) {