@react-aria/focus 3.5.2 → 3.5.5
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/main.js +168 -165
- package/dist/main.js.map +1 -1
- package/dist/module.js +164 -161
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +7 -265
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/FocusScope.tsx +1 -1
- package/src/useFocusable.tsx +9 -3
package/dist/module.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import $
|
|
2
|
-
import {useLayoutEffect as $
|
|
3
|
-
import {getInteractionModality as $
|
|
4
|
-
import $
|
|
1
|
+
import $6nfFC$react, {useRef as $6nfFC$useRef, useContext as $6nfFC$useContext, useEffect as $6nfFC$useEffect, useState as $6nfFC$useState} from "react";
|
|
2
|
+
import {useLayoutEffect as $6nfFC$useLayoutEffect, runAfterTransition as $6nfFC$runAfterTransition, focusWithoutScrolling as $6nfFC$focusWithoutScrolling, mergeProps as $6nfFC$mergeProps, useSyncRef as $6nfFC$useSyncRef} from "@react-aria/utils";
|
|
3
|
+
import {getInteractionModality as $6nfFC$getInteractionModality, isFocusVisible as $6nfFC$isFocusVisible, useFocusVisibleListener as $6nfFC$useFocusVisibleListener, useFocus as $6nfFC$useFocus, useFocusWithin as $6nfFC$useFocusWithin, useKeyboard as $6nfFC$useKeyboard} from "@react-aria/interactions";
|
|
4
|
+
import $6nfFC$clsx from "clsx";
|
|
5
5
|
|
|
6
6
|
function $parcel$export(e, n, v, s) {
|
|
7
7
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
8
8
|
}
|
|
9
|
-
var $
|
|
9
|
+
var $9bf71ea28793e738$exports = {};
|
|
10
10
|
|
|
11
|
-
$parcel$export($
|
|
12
|
-
$parcel$export($
|
|
13
|
-
$parcel$export($
|
|
14
|
-
$parcel$export($
|
|
15
|
-
var $
|
|
11
|
+
$parcel$export($9bf71ea28793e738$exports, "FocusScope", () => $9bf71ea28793e738$export$20e40289641fbbb6);
|
|
12
|
+
$parcel$export($9bf71ea28793e738$exports, "useFocusManager", () => $9bf71ea28793e738$export$10c5169755ce7bd7);
|
|
13
|
+
$parcel$export($9bf71ea28793e738$exports, "getFocusableTreeWalker", () => $9bf71ea28793e738$export$2d6ec8fc375ceafa);
|
|
14
|
+
$parcel$export($9bf71ea28793e738$exports, "createFocusManager", () => $9bf71ea28793e738$export$c5251b9e124bf29);
|
|
15
|
+
var $6a99195332edec8b$exports = {};
|
|
16
16
|
|
|
17
|
-
$parcel$export($
|
|
17
|
+
$parcel$export($6a99195332edec8b$exports, "focusSafely", () => $6a99195332edec8b$export$80f3e147d781571c);
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
function $
|
|
20
|
+
function $6a99195332edec8b$export$80f3e147d781571c(element) {
|
|
21
21
|
// If the user is interacting with a virtual cursor, e.g. screen reader, then
|
|
22
22
|
// wait until after any animated transitions that are currently occurring on
|
|
23
23
|
// the page before shifting focus. This avoids issues with VoiceOver on iOS
|
|
24
24
|
// causing the page to scroll when moving focus if the element is transitioning
|
|
25
25
|
// from off the screen.
|
|
26
|
-
if ($
|
|
26
|
+
if ($6nfFC$getInteractionModality() === 'virtual') {
|
|
27
27
|
let lastFocusedElement = document.activeElement;
|
|
28
|
-
$
|
|
28
|
+
$6nfFC$runAfterTransition(()=>{
|
|
29
29
|
// If focus did not move and the element is still in the document, focus it.
|
|
30
|
-
if (document.activeElement === lastFocusedElement && document.contains(element)) $
|
|
30
|
+
if (document.activeElement === lastFocusedElement && document.contains(element)) $6nfFC$focusWithoutScrolling(element);
|
|
31
31
|
});
|
|
32
|
-
} else $
|
|
32
|
+
} else $6nfFC$focusWithoutScrolling(element);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
|
|
@@ -43,7 +43,7 @@ function $1159c3b6ba210e4f$export$80f3e147d781571c(element) {
|
|
|
43
43
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
44
44
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
45
45
|
* governing permissions and limitations under the License.
|
|
46
|
-
*/ function $
|
|
46
|
+
*/ function $645f2e67b85a24c9$var$isStyleVisible(element) {
|
|
47
47
|
if (!(element instanceof HTMLElement) && !(element instanceof SVGElement)) return false;
|
|
48
48
|
let { display: display , visibility: visibility } = element.style;
|
|
49
49
|
let isVisible = display !== 'none' && visibility !== 'hidden' && visibility !== 'collapse';
|
|
@@ -54,27 +54,27 @@ function $1159c3b6ba210e4f$export$80f3e147d781571c(element) {
|
|
|
54
54
|
}
|
|
55
55
|
return isVisible;
|
|
56
56
|
}
|
|
57
|
-
function $
|
|
57
|
+
function $645f2e67b85a24c9$var$isAttributeVisible(element, childElement) {
|
|
58
58
|
return !element.hasAttribute('hidden') && (element.nodeName === 'DETAILS' && childElement && childElement.nodeName !== 'SUMMARY' ? element.hasAttribute('open') : true);
|
|
59
59
|
}
|
|
60
|
-
function $
|
|
61
|
-
return element.nodeName !== '#comment' && $
|
|
60
|
+
function $645f2e67b85a24c9$export$e989c0fffaa6b27a(element, childElement) {
|
|
61
|
+
return element.nodeName !== '#comment' && $645f2e67b85a24c9$var$isStyleVisible(element) && $645f2e67b85a24c9$var$isAttributeVisible(element, childElement) && (!element.parentElement || $645f2e67b85a24c9$export$e989c0fffaa6b27a(element.parentElement, element));
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
|
|
65
65
|
|
|
66
66
|
|
|
67
|
-
const $
|
|
68
|
-
let $
|
|
69
|
-
let $
|
|
70
|
-
function $
|
|
67
|
+
const $9bf71ea28793e738$var$FocusContext = /*#__PURE__*/ $6nfFC$react.createContext(null);
|
|
68
|
+
let $9bf71ea28793e738$var$activeScope = null;
|
|
69
|
+
let $9bf71ea28793e738$var$scopes = new Map();
|
|
70
|
+
function $9bf71ea28793e738$export$20e40289641fbbb6(props) {
|
|
71
71
|
let { children: children , contain: contain , restoreFocus: restoreFocus , autoFocus: autoFocus } = props;
|
|
72
|
-
let startRef = $
|
|
73
|
-
let endRef = $
|
|
74
|
-
let scopeRef = $
|
|
75
|
-
let ctx = $
|
|
72
|
+
let startRef = $6nfFC$useRef();
|
|
73
|
+
let endRef = $6nfFC$useRef();
|
|
74
|
+
let scopeRef = $6nfFC$useRef([]);
|
|
75
|
+
let ctx = $6nfFC$useContext($9bf71ea28793e738$var$FocusContext);
|
|
76
76
|
let parentScope = ctx === null || ctx === void 0 ? void 0 : ctx.scopeRef;
|
|
77
|
-
$
|
|
77
|
+
$6nfFC$useLayoutEffect(()=>{
|
|
78
78
|
// Find all rendered nodes between the sentinels and add them to the scope.
|
|
79
79
|
let node = startRef.current.nextSibling;
|
|
80
80
|
let nodes = [];
|
|
@@ -87,43 +87,43 @@ function $14e5c84cbc2e6e2e$export$20e40289641fbbb6(props) {
|
|
|
87
87
|
children,
|
|
88
88
|
parentScope
|
|
89
89
|
]);
|
|
90
|
-
$
|
|
91
|
-
$
|
|
90
|
+
$6nfFC$useLayoutEffect(()=>{
|
|
91
|
+
$9bf71ea28793e738$var$scopes.set(scopeRef, parentScope);
|
|
92
92
|
return ()=>{
|
|
93
93
|
// Restore the active scope on unmount if this scope or a descendant scope is active.
|
|
94
94
|
// Parent effect cleanups run before children, so we need to check if the
|
|
95
95
|
// parent scope actually still exists before restoring the active scope to it.
|
|
96
|
-
if ((scopeRef === $
|
|
97
|
-
$
|
|
96
|
+
if ((scopeRef === $9bf71ea28793e738$var$activeScope || $9bf71ea28793e738$var$isAncestorScope(scopeRef, $9bf71ea28793e738$var$activeScope)) && (!parentScope || $9bf71ea28793e738$var$scopes.has(parentScope))) $9bf71ea28793e738$var$activeScope = parentScope;
|
|
97
|
+
$9bf71ea28793e738$var$scopes.delete(scopeRef);
|
|
98
98
|
};
|
|
99
99
|
}, [
|
|
100
100
|
scopeRef,
|
|
101
101
|
parentScope
|
|
102
102
|
]);
|
|
103
|
-
$
|
|
104
|
-
$
|
|
105
|
-
$
|
|
106
|
-
let focusManager = $
|
|
107
|
-
return(/*#__PURE__*/ $
|
|
103
|
+
$9bf71ea28793e738$var$useFocusContainment(scopeRef, contain);
|
|
104
|
+
$9bf71ea28793e738$var$useRestoreFocus(scopeRef, restoreFocus, contain);
|
|
105
|
+
$9bf71ea28793e738$var$useAutoFocus(scopeRef, autoFocus);
|
|
106
|
+
let focusManager = $9bf71ea28793e738$var$createFocusManagerForScope(scopeRef);
|
|
107
|
+
return(/*#__PURE__*/ $6nfFC$react.createElement($9bf71ea28793e738$var$FocusContext.Provider, {
|
|
108
108
|
value: {
|
|
109
109
|
scopeRef: scopeRef,
|
|
110
110
|
focusManager: focusManager
|
|
111
111
|
}
|
|
112
|
-
}, /*#__PURE__*/ $
|
|
112
|
+
}, /*#__PURE__*/ $6nfFC$react.createElement("span", {
|
|
113
113
|
"data-focus-scope-start": true,
|
|
114
114
|
hidden: true,
|
|
115
115
|
ref: startRef
|
|
116
|
-
}), children, /*#__PURE__*/ $
|
|
116
|
+
}), children, /*#__PURE__*/ $6nfFC$react.createElement("span", {
|
|
117
117
|
"data-focus-scope-end": true,
|
|
118
118
|
hidden: true,
|
|
119
119
|
ref: endRef
|
|
120
120
|
})));
|
|
121
121
|
}
|
|
122
|
-
function $
|
|
122
|
+
function $9bf71ea28793e738$export$10c5169755ce7bd7() {
|
|
123
123
|
var ref;
|
|
124
|
-
return (ref = $
|
|
124
|
+
return (ref = $6nfFC$useContext($9bf71ea28793e738$var$FocusContext)) === null || ref === void 0 ? void 0 : ref.focusManager;
|
|
125
125
|
}
|
|
126
|
-
function $
|
|
126
|
+
function $9bf71ea28793e738$var$createFocusManagerForScope(scopeRef) {
|
|
127
127
|
return {
|
|
128
128
|
focusNext (opts = {
|
|
129
129
|
}) {
|
|
@@ -131,16 +131,16 @@ function $14e5c84cbc2e6e2e$var$createFocusManagerForScope(scopeRef) {
|
|
|
131
131
|
let { from: from , tabbable: tabbable , wrap: wrap } = opts;
|
|
132
132
|
let node = from || document.activeElement;
|
|
133
133
|
let sentinel = scope[0].previousElementSibling;
|
|
134
|
-
let walker = $
|
|
134
|
+
let walker = $9bf71ea28793e738$export$2d6ec8fc375ceafa($9bf71ea28793e738$var$getScopeRoot(scope), {
|
|
135
135
|
tabbable: tabbable
|
|
136
136
|
}, scope);
|
|
137
|
-
walker.currentNode = $
|
|
137
|
+
walker.currentNode = $9bf71ea28793e738$var$isElementInScope(node, scope) ? node : sentinel;
|
|
138
138
|
let nextNode = walker.nextNode();
|
|
139
139
|
if (!nextNode && wrap) {
|
|
140
140
|
walker.currentNode = sentinel;
|
|
141
141
|
nextNode = walker.nextNode();
|
|
142
142
|
}
|
|
143
|
-
if (nextNode) $
|
|
143
|
+
if (nextNode) $9bf71ea28793e738$var$focusElement(nextNode, true);
|
|
144
144
|
return nextNode;
|
|
145
145
|
},
|
|
146
146
|
focusPrevious (opts = {
|
|
@@ -149,45 +149,45 @@ function $14e5c84cbc2e6e2e$var$createFocusManagerForScope(scopeRef) {
|
|
|
149
149
|
let { from: from , tabbable: tabbable , wrap: wrap } = opts;
|
|
150
150
|
let node = from || document.activeElement;
|
|
151
151
|
let sentinel = scope[scope.length - 1].nextElementSibling;
|
|
152
|
-
let walker = $
|
|
152
|
+
let walker = $9bf71ea28793e738$export$2d6ec8fc375ceafa($9bf71ea28793e738$var$getScopeRoot(scope), {
|
|
153
153
|
tabbable: tabbable
|
|
154
154
|
}, scope);
|
|
155
|
-
walker.currentNode = $
|
|
155
|
+
walker.currentNode = $9bf71ea28793e738$var$isElementInScope(node, scope) ? node : sentinel;
|
|
156
156
|
let previousNode = walker.previousNode();
|
|
157
157
|
if (!previousNode && wrap) {
|
|
158
158
|
walker.currentNode = sentinel;
|
|
159
159
|
previousNode = walker.previousNode();
|
|
160
160
|
}
|
|
161
|
-
if (previousNode) $
|
|
161
|
+
if (previousNode) $9bf71ea28793e738$var$focusElement(previousNode, true);
|
|
162
162
|
return previousNode;
|
|
163
163
|
},
|
|
164
164
|
focusFirst (opts = {
|
|
165
165
|
}) {
|
|
166
166
|
let scope = scopeRef.current;
|
|
167
167
|
let { tabbable: tabbable } = opts;
|
|
168
|
-
let walker = $
|
|
168
|
+
let walker = $9bf71ea28793e738$export$2d6ec8fc375ceafa($9bf71ea28793e738$var$getScopeRoot(scope), {
|
|
169
169
|
tabbable: tabbable
|
|
170
170
|
}, scope);
|
|
171
171
|
walker.currentNode = scope[0].previousElementSibling;
|
|
172
172
|
let nextNode = walker.nextNode();
|
|
173
|
-
if (nextNode) $
|
|
173
|
+
if (nextNode) $9bf71ea28793e738$var$focusElement(nextNode, true);
|
|
174
174
|
return nextNode;
|
|
175
175
|
},
|
|
176
176
|
focusLast (opts = {
|
|
177
177
|
}) {
|
|
178
178
|
let scope = scopeRef.current;
|
|
179
179
|
let { tabbable: tabbable } = opts;
|
|
180
|
-
let walker = $
|
|
180
|
+
let walker = $9bf71ea28793e738$export$2d6ec8fc375ceafa($9bf71ea28793e738$var$getScopeRoot(scope), {
|
|
181
181
|
tabbable: tabbable
|
|
182
182
|
}, scope);
|
|
183
183
|
walker.currentNode = scope[scope.length - 1].nextElementSibling;
|
|
184
184
|
let previousNode = walker.previousNode();
|
|
185
|
-
if (previousNode) $
|
|
185
|
+
if (previousNode) $9bf71ea28793e738$var$focusElement(previousNode, true);
|
|
186
186
|
return previousNode;
|
|
187
187
|
}
|
|
188
188
|
};
|
|
189
189
|
}
|
|
190
|
-
const $
|
|
190
|
+
const $9bf71ea28793e738$var$focusableElements = [
|
|
191
191
|
'input:not([disabled]):not([type=hidden])',
|
|
192
192
|
'select:not([disabled])',
|
|
193
193
|
'textarea:not([disabled])',
|
|
@@ -202,25 +202,25 @@ const $14e5c84cbc2e6e2e$var$focusableElements = [
|
|
|
202
202
|
'video[controls]',
|
|
203
203
|
'[contenteditable]'
|
|
204
204
|
];
|
|
205
|
-
const $
|
|
206
|
-
$
|
|
207
|
-
const $
|
|
208
|
-
function $
|
|
205
|
+
const $9bf71ea28793e738$var$FOCUSABLE_ELEMENT_SELECTOR = $9bf71ea28793e738$var$focusableElements.join(':not([hidden]),') + ',[tabindex]:not([disabled]):not([hidden])';
|
|
206
|
+
$9bf71ea28793e738$var$focusableElements.push('[tabindex]:not([tabindex="-1"]):not([disabled])');
|
|
207
|
+
const $9bf71ea28793e738$var$TABBABLE_ELEMENT_SELECTOR = $9bf71ea28793e738$var$focusableElements.join(':not([hidden]):not([tabindex="-1"]),');
|
|
208
|
+
function $9bf71ea28793e738$var$getScopeRoot(scope) {
|
|
209
209
|
return scope[0].parentElement;
|
|
210
210
|
}
|
|
211
|
-
function $
|
|
212
|
-
let focusedNode = $
|
|
213
|
-
let raf = $
|
|
214
|
-
$
|
|
211
|
+
function $9bf71ea28793e738$var$useFocusContainment(scopeRef, contain) {
|
|
212
|
+
let focusedNode = $6nfFC$useRef();
|
|
213
|
+
let raf = $6nfFC$useRef(null);
|
|
214
|
+
$6nfFC$useLayoutEffect(()=>{
|
|
215
215
|
let scope1 = scopeRef.current;
|
|
216
216
|
if (!contain) return;
|
|
217
217
|
// Handle the Tab key to contain focus within the scope
|
|
218
218
|
let onKeyDown = (e)=>{
|
|
219
|
-
if (e.key !== 'Tab' || e.altKey || e.ctrlKey || e.metaKey || scopeRef !== $
|
|
219
|
+
if (e.key !== 'Tab' || e.altKey || e.ctrlKey || e.metaKey || scopeRef !== $9bf71ea28793e738$var$activeScope) return;
|
|
220
220
|
let focusedElement = document.activeElement;
|
|
221
221
|
let scope = scopeRef.current;
|
|
222
|
-
if (!$
|
|
223
|
-
let walker = $
|
|
222
|
+
if (!$9bf71ea28793e738$var$isElementInScope(focusedElement, scope)) return;
|
|
223
|
+
let walker = $9bf71ea28793e738$export$2d6ec8fc375ceafa($9bf71ea28793e738$var$getScopeRoot(scope), {
|
|
224
224
|
tabbable: true
|
|
225
225
|
}, scope);
|
|
226
226
|
walker.currentNode = focusedElement;
|
|
@@ -230,27 +230,27 @@ function $14e5c84cbc2e6e2e$var$useFocusContainment(scopeRef, contain) {
|
|
|
230
230
|
nextElement = e.shiftKey ? walker.previousNode() : walker.nextNode();
|
|
231
231
|
}
|
|
232
232
|
e.preventDefault();
|
|
233
|
-
if (nextElement) $
|
|
233
|
+
if (nextElement) $9bf71ea28793e738$var$focusElement(nextElement, true);
|
|
234
234
|
};
|
|
235
235
|
let onFocus = (e)=>{
|
|
236
236
|
// If focusing an element in a child scope of the currently active scope, the child becomes active.
|
|
237
237
|
// Moving out of the active scope to an ancestor is not allowed.
|
|
238
|
-
if (!$
|
|
239
|
-
$
|
|
238
|
+
if (!$9bf71ea28793e738$var$activeScope || $9bf71ea28793e738$var$isAncestorScope($9bf71ea28793e738$var$activeScope, scopeRef)) {
|
|
239
|
+
$9bf71ea28793e738$var$activeScope = scopeRef;
|
|
240
240
|
focusedNode.current = e.target;
|
|
241
|
-
} else if (scopeRef === $
|
|
241
|
+
} else if (scopeRef === $9bf71ea28793e738$var$activeScope && !$9bf71ea28793e738$var$isElementInChildScope(e.target, scopeRef)) {
|
|
242
242
|
// If a focus event occurs outside the active scope (e.g. user tabs from browser location bar),
|
|
243
243
|
// restore focus to the previously focused node or the first tabbable element in the active scope.
|
|
244
244
|
if (focusedNode.current) focusedNode.current.focus();
|
|
245
|
-
else if ($
|
|
246
|
-
} else if (scopeRef === $
|
|
245
|
+
else if ($9bf71ea28793e738$var$activeScope) $9bf71ea28793e738$var$focusFirstInScope($9bf71ea28793e738$var$activeScope.current);
|
|
246
|
+
} else if (scopeRef === $9bf71ea28793e738$var$activeScope) focusedNode.current = e.target;
|
|
247
247
|
};
|
|
248
248
|
let onBlur = (e)=>{
|
|
249
249
|
// Firefox doesn't shift focus back to the Dialog properly without this
|
|
250
250
|
raf.current = requestAnimationFrame(()=>{
|
|
251
251
|
// Use document.activeElement instead of e.relatedTarget so we can tell if user clicked into iframe
|
|
252
|
-
if (scopeRef === $
|
|
253
|
-
$
|
|
252
|
+
if (scopeRef === $9bf71ea28793e738$var$activeScope && !$9bf71ea28793e738$var$isElementInChildScope(document.activeElement, scopeRef)) {
|
|
253
|
+
$9bf71ea28793e738$var$activeScope = scopeRef;
|
|
254
254
|
focusedNode.current = e.target;
|
|
255
255
|
focusedNode.current.focus();
|
|
256
256
|
}
|
|
@@ -275,40 +275,40 @@ function $14e5c84cbc2e6e2e$var$useFocusContainment(scopeRef, contain) {
|
|
|
275
275
|
contain
|
|
276
276
|
]);
|
|
277
277
|
// eslint-disable-next-line arrow-body-style
|
|
278
|
-
$
|
|
278
|
+
$6nfFC$useEffect(()=>{
|
|
279
279
|
return ()=>cancelAnimationFrame(raf.current)
|
|
280
280
|
;
|
|
281
281
|
}, [
|
|
282
282
|
raf
|
|
283
283
|
]);
|
|
284
284
|
}
|
|
285
|
-
function $
|
|
286
|
-
for (let scope of $
|
|
287
|
-
if ($
|
|
285
|
+
function $9bf71ea28793e738$var$isElementInAnyScope(element) {
|
|
286
|
+
for (let scope of $9bf71ea28793e738$var$scopes.keys()){
|
|
287
|
+
if ($9bf71ea28793e738$var$isElementInScope(element, scope.current)) return true;
|
|
288
288
|
}
|
|
289
289
|
return false;
|
|
290
290
|
}
|
|
291
|
-
function $
|
|
291
|
+
function $9bf71ea28793e738$var$isElementInScope(element, scope) {
|
|
292
292
|
return scope.some((node)=>node.contains(element)
|
|
293
293
|
);
|
|
294
294
|
}
|
|
295
|
-
function $
|
|
295
|
+
function $9bf71ea28793e738$var$isElementInChildScope(element, scope) {
|
|
296
296
|
// node.contains in isElementInScope covers child scopes that are also DOM children,
|
|
297
297
|
// but does not cover child scopes in portals.
|
|
298
|
-
for (let s of $
|
|
299
|
-
if ((s === scope || $
|
|
298
|
+
for (let s of $9bf71ea28793e738$var$scopes.keys()){
|
|
299
|
+
if ((s === scope || $9bf71ea28793e738$var$isAncestorScope(scope, s)) && $9bf71ea28793e738$var$isElementInScope(element, s.current)) return true;
|
|
300
300
|
}
|
|
301
301
|
return false;
|
|
302
302
|
}
|
|
303
|
-
function $
|
|
304
|
-
let parent = $
|
|
303
|
+
function $9bf71ea28793e738$var$isAncestorScope(ancestor, scope) {
|
|
304
|
+
let parent = $9bf71ea28793e738$var$scopes.get(scope);
|
|
305
305
|
if (!parent) return false;
|
|
306
306
|
if (parent === ancestor) return true;
|
|
307
|
-
return $
|
|
307
|
+
return $9bf71ea28793e738$var$isAncestorScope(ancestor, parent);
|
|
308
308
|
}
|
|
309
|
-
function $
|
|
309
|
+
function $9bf71ea28793e738$var$focusElement(element, scroll = false) {
|
|
310
310
|
if (element != null && !scroll) try {
|
|
311
|
-
$
|
|
311
|
+
$6a99195332edec8b$export$80f3e147d781571c(element);
|
|
312
312
|
} catch (err) {
|
|
313
313
|
// ignore
|
|
314
314
|
}
|
|
@@ -318,29 +318,29 @@ function $14e5c84cbc2e6e2e$var$focusElement(element, scroll = false) {
|
|
|
318
318
|
// ignore
|
|
319
319
|
}
|
|
320
320
|
}
|
|
321
|
-
function $
|
|
321
|
+
function $9bf71ea28793e738$var$focusFirstInScope(scope) {
|
|
322
322
|
let sentinel = scope[0].previousElementSibling;
|
|
323
|
-
let walker = $
|
|
323
|
+
let walker = $9bf71ea28793e738$export$2d6ec8fc375ceafa($9bf71ea28793e738$var$getScopeRoot(scope), {
|
|
324
324
|
tabbable: true
|
|
325
325
|
}, scope);
|
|
326
326
|
walker.currentNode = sentinel;
|
|
327
|
-
$
|
|
327
|
+
$9bf71ea28793e738$var$focusElement(walker.nextNode());
|
|
328
328
|
}
|
|
329
|
-
function $
|
|
330
|
-
const autoFocusRef = $
|
|
331
|
-
$
|
|
329
|
+
function $9bf71ea28793e738$var$useAutoFocus(scopeRef, autoFocus) {
|
|
330
|
+
const autoFocusRef = $6nfFC$react.useRef(autoFocus);
|
|
331
|
+
$6nfFC$useEffect(()=>{
|
|
332
332
|
if (autoFocusRef.current) {
|
|
333
|
-
$
|
|
334
|
-
if (!$
|
|
333
|
+
$9bf71ea28793e738$var$activeScope = scopeRef;
|
|
334
|
+
if (!$9bf71ea28793e738$var$isElementInScope(document.activeElement, $9bf71ea28793e738$var$activeScope.current)) $9bf71ea28793e738$var$focusFirstInScope(scopeRef.current);
|
|
335
335
|
}
|
|
336
336
|
autoFocusRef.current = false;
|
|
337
337
|
}, []);
|
|
338
338
|
}
|
|
339
|
-
function $
|
|
339
|
+
function $9bf71ea28793e738$var$useRestoreFocus(scopeRef, restoreFocus, contain) {
|
|
340
340
|
// create a ref during render instead of useLayoutEffect so the active element is saved before a child with autoFocus=true mounts.
|
|
341
|
-
const nodeToRestoreRef = $
|
|
341
|
+
const nodeToRestoreRef = $6nfFC$useRef(typeof document !== 'undefined' ? document.activeElement : null);
|
|
342
342
|
// useLayoutEffect instead of useEffect so the active element is saved synchronously instead of asynchronously.
|
|
343
|
-
$
|
|
343
|
+
$6nfFC$useLayoutEffect(()=>{
|
|
344
344
|
let nodeToRestore = nodeToRestoreRef.current;
|
|
345
345
|
if (!restoreFocus) return;
|
|
346
346
|
// Handle the Tab key so that tabbing out of the scope goes to the next element
|
|
@@ -350,9 +350,9 @@ function $14e5c84cbc2e6e2e$var$useRestoreFocus(scopeRef, restoreFocus, contain)
|
|
|
350
350
|
let onKeyDown = (e)=>{
|
|
351
351
|
if (e.key !== 'Tab' || e.altKey || e.ctrlKey || e.metaKey) return;
|
|
352
352
|
let focusedElement = document.activeElement;
|
|
353
|
-
if (!$
|
|
353
|
+
if (!$9bf71ea28793e738$var$isElementInScope(focusedElement, scopeRef.current)) return;
|
|
354
354
|
// Create a DOM tree walker that matches all tabbable elements
|
|
355
|
-
let walker = $
|
|
355
|
+
let walker = $9bf71ea28793e738$export$2d6ec8fc375ceafa(document.body, {
|
|
356
356
|
tabbable: true
|
|
357
357
|
});
|
|
358
358
|
// Find the next tabbable element after the currently focused element
|
|
@@ -361,26 +361,26 @@ function $14e5c84cbc2e6e2e$var$useRestoreFocus(scopeRef, restoreFocus, contain)
|
|
|
361
361
|
if (!document.body.contains(nodeToRestore) || nodeToRestore === document.body) nodeToRestore = null;
|
|
362
362
|
// If there is no next element, or it is outside the current scope, move focus to the
|
|
363
363
|
// next element after the node to restore to instead.
|
|
364
|
-
if ((!nextElement || !$
|
|
364
|
+
if ((!nextElement || !$9bf71ea28793e738$var$isElementInScope(nextElement, scopeRef.current)) && nodeToRestore) {
|
|
365
365
|
walker.currentNode = nodeToRestore;
|
|
366
366
|
// Skip over elements within the scope, in case the scope immediately follows the node to restore.
|
|
367
367
|
do nextElement = e.shiftKey ? walker.previousNode() : walker.nextNode();
|
|
368
|
-
while ($
|
|
368
|
+
while ($9bf71ea28793e738$var$isElementInScope(nextElement, scopeRef.current))
|
|
369
369
|
e.preventDefault();
|
|
370
370
|
e.stopPropagation();
|
|
371
|
-
if (nextElement) $
|
|
371
|
+
if (nextElement) $9bf71ea28793e738$var$focusElement(nextElement, true);
|
|
372
372
|
else // If there is no next element and the nodeToRestore isn't within a FocusScope (i.e. we are leaving the top level focus scope)
|
|
373
373
|
// then move focus to the body.
|
|
374
374
|
// Otherwise restore focus to the nodeToRestore (e.g menu within a popover -> tabbing to close the menu should move focus to menu trigger)
|
|
375
|
-
if (!$
|
|
376
|
-
else $
|
|
375
|
+
if (!$9bf71ea28793e738$var$isElementInAnyScope(nodeToRestore)) focusedElement.blur();
|
|
376
|
+
else $9bf71ea28793e738$var$focusElement(nodeToRestore, true);
|
|
377
377
|
}
|
|
378
378
|
};
|
|
379
379
|
if (!contain) document.addEventListener('keydown', onKeyDown, true);
|
|
380
380
|
return ()=>{
|
|
381
381
|
if (!contain) document.removeEventListener('keydown', onKeyDown, true);
|
|
382
|
-
if (restoreFocus && nodeToRestore && $
|
|
383
|
-
if (document.body.contains(nodeToRestore)) $
|
|
382
|
+
if (restoreFocus && nodeToRestore && $9bf71ea28793e738$var$isElementInScope(document.activeElement, scopeRef.current)) requestAnimationFrame(()=>{
|
|
383
|
+
if (document.body.contains(nodeToRestore)) $9bf71ea28793e738$var$focusElement(nodeToRestore);
|
|
384
384
|
});
|
|
385
385
|
};
|
|
386
386
|
}, [
|
|
@@ -389,28 +389,28 @@ function $14e5c84cbc2e6e2e$var$useRestoreFocus(scopeRef, restoreFocus, contain)
|
|
|
389
389
|
contain
|
|
390
390
|
]);
|
|
391
391
|
}
|
|
392
|
-
function $
|
|
393
|
-
let selector = (opts === null || opts === void 0 ? void 0 : opts.tabbable) ? $
|
|
392
|
+
function $9bf71ea28793e738$export$2d6ec8fc375ceafa(root, opts, scope) {
|
|
393
|
+
let selector = (opts === null || opts === void 0 ? void 0 : opts.tabbable) ? $9bf71ea28793e738$var$TABBABLE_ELEMENT_SELECTOR : $9bf71ea28793e738$var$FOCUSABLE_ELEMENT_SELECTOR;
|
|
394
394
|
let walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, {
|
|
395
395
|
acceptNode (node) {
|
|
396
396
|
var ref;
|
|
397
397
|
// Skip nodes inside the starting node.
|
|
398
398
|
if (opts === null || opts === void 0 ? void 0 : (ref = opts.from) === null || ref === void 0 ? void 0 : ref.contains(node)) return NodeFilter.FILTER_REJECT;
|
|
399
|
-
if (node.matches(selector) && $
|
|
399
|
+
if (node.matches(selector) && $645f2e67b85a24c9$export$e989c0fffaa6b27a(node) && (!scope || $9bf71ea28793e738$var$isElementInScope(node, scope))) return NodeFilter.FILTER_ACCEPT;
|
|
400
400
|
return NodeFilter.FILTER_SKIP;
|
|
401
401
|
}
|
|
402
402
|
});
|
|
403
403
|
if (opts === null || opts === void 0 ? void 0 : opts.from) walker.currentNode = opts.from;
|
|
404
404
|
return walker;
|
|
405
405
|
}
|
|
406
|
-
function $
|
|
406
|
+
function $9bf71ea28793e738$export$c5251b9e124bf29(ref) {
|
|
407
407
|
return {
|
|
408
408
|
focusNext (opts = {
|
|
409
409
|
}) {
|
|
410
410
|
let root = ref.current;
|
|
411
411
|
let { from: from , tabbable: tabbable , wrap: wrap } = opts;
|
|
412
412
|
let node = from || document.activeElement;
|
|
413
|
-
let walker = $
|
|
413
|
+
let walker = $9bf71ea28793e738$export$2d6ec8fc375ceafa(root, {
|
|
414
414
|
tabbable: tabbable
|
|
415
415
|
});
|
|
416
416
|
if (root.contains(node)) walker.currentNode = node;
|
|
@@ -419,7 +419,7 @@ function $14e5c84cbc2e6e2e$export$c5251b9e124bf29(ref) {
|
|
|
419
419
|
walker.currentNode = root;
|
|
420
420
|
nextNode = walker.nextNode();
|
|
421
421
|
}
|
|
422
|
-
if (nextNode) $
|
|
422
|
+
if (nextNode) $9bf71ea28793e738$var$focusElement(nextNode, true);
|
|
423
423
|
return nextNode;
|
|
424
424
|
},
|
|
425
425
|
focusPrevious (opts = {
|
|
@@ -427,48 +427,48 @@ function $14e5c84cbc2e6e2e$export$c5251b9e124bf29(ref) {
|
|
|
427
427
|
let root = ref.current;
|
|
428
428
|
let { from: from , tabbable: tabbable , wrap: wrap } = opts;
|
|
429
429
|
let node = from || document.activeElement;
|
|
430
|
-
let walker = $
|
|
430
|
+
let walker = $9bf71ea28793e738$export$2d6ec8fc375ceafa(root, {
|
|
431
431
|
tabbable: tabbable
|
|
432
432
|
});
|
|
433
433
|
if (root.contains(node)) walker.currentNode = node;
|
|
434
434
|
else {
|
|
435
|
-
let next = $
|
|
436
|
-
if (next) $
|
|
435
|
+
let next = $9bf71ea28793e738$var$last(walker);
|
|
436
|
+
if (next) $9bf71ea28793e738$var$focusElement(next, true);
|
|
437
437
|
return next;
|
|
438
438
|
}
|
|
439
439
|
let previousNode = walker.previousNode();
|
|
440
440
|
if (!previousNode && wrap) {
|
|
441
441
|
walker.currentNode = root;
|
|
442
|
-
previousNode = $
|
|
442
|
+
previousNode = $9bf71ea28793e738$var$last(walker);
|
|
443
443
|
}
|
|
444
|
-
if (previousNode) $
|
|
444
|
+
if (previousNode) $9bf71ea28793e738$var$focusElement(previousNode, true);
|
|
445
445
|
return previousNode;
|
|
446
446
|
},
|
|
447
447
|
focusFirst (opts = {
|
|
448
448
|
}) {
|
|
449
449
|
let root = ref.current;
|
|
450
450
|
let { tabbable: tabbable } = opts;
|
|
451
|
-
let walker = $
|
|
451
|
+
let walker = $9bf71ea28793e738$export$2d6ec8fc375ceafa(root, {
|
|
452
452
|
tabbable: tabbable
|
|
453
453
|
});
|
|
454
454
|
let nextNode = walker.nextNode();
|
|
455
|
-
if (nextNode) $
|
|
455
|
+
if (nextNode) $9bf71ea28793e738$var$focusElement(nextNode, true);
|
|
456
456
|
return nextNode;
|
|
457
457
|
},
|
|
458
458
|
focusLast (opts = {
|
|
459
459
|
}) {
|
|
460
460
|
let root = ref.current;
|
|
461
461
|
let { tabbable: tabbable } = opts;
|
|
462
|
-
let walker = $
|
|
462
|
+
let walker = $9bf71ea28793e738$export$2d6ec8fc375ceafa(root, {
|
|
463
463
|
tabbable: tabbable
|
|
464
464
|
});
|
|
465
|
-
let next = $
|
|
466
|
-
if (next) $
|
|
465
|
+
let next = $9bf71ea28793e738$var$last(walker);
|
|
466
|
+
if (next) $9bf71ea28793e738$var$focusElement(next, true);
|
|
467
467
|
return next;
|
|
468
468
|
}
|
|
469
469
|
};
|
|
470
470
|
}
|
|
471
|
-
function $
|
|
471
|
+
function $9bf71ea28793e738$var$last(walker) {
|
|
472
472
|
let next;
|
|
473
473
|
let last;
|
|
474
474
|
do {
|
|
@@ -479,27 +479,27 @@ function $14e5c84cbc2e6e2e$var$last(walker) {
|
|
|
479
479
|
}
|
|
480
480
|
|
|
481
481
|
|
|
482
|
-
var $
|
|
482
|
+
var $907718708eab68af$exports = {};
|
|
483
483
|
|
|
484
|
-
$parcel$export($
|
|
484
|
+
$parcel$export($907718708eab68af$exports, "FocusRing", () => $907718708eab68af$export$1a38b4ad7f578e1d);
|
|
485
485
|
|
|
486
486
|
|
|
487
487
|
|
|
488
|
-
var $
|
|
488
|
+
var $f7dceffc5ad7768b$exports = {};
|
|
489
489
|
|
|
490
|
-
$parcel$export($
|
|
490
|
+
$parcel$export($f7dceffc5ad7768b$exports, "useFocusRing", () => $f7dceffc5ad7768b$export$4e328f61c538687f);
|
|
491
491
|
|
|
492
492
|
|
|
493
493
|
|
|
494
|
-
function $
|
|
494
|
+
function $f7dceffc5ad7768b$export$4e328f61c538687f(props = {
|
|
495
495
|
}) {
|
|
496
496
|
let { autoFocus: autoFocus = false , isTextInput: isTextInput , within: within } = props;
|
|
497
|
-
let state = $
|
|
497
|
+
let state = $6nfFC$useRef({
|
|
498
498
|
isFocused: false,
|
|
499
|
-
isFocusVisible: autoFocus || $
|
|
499
|
+
isFocusVisible: autoFocus || $6nfFC$isFocusVisible()
|
|
500
500
|
}).current;
|
|
501
|
-
let [isFocused1, setFocused] = $
|
|
502
|
-
let [isFocusVisibleState, setFocusVisible] = $
|
|
501
|
+
let [isFocused1, setFocused] = $6nfFC$useState(false);
|
|
502
|
+
let [isFocusVisibleState, setFocusVisible] = $6nfFC$useState(()=>state.isFocused && state.isFocusVisible
|
|
503
503
|
);
|
|
504
504
|
let updateState = ()=>setFocusVisible(state.isFocused && state.isFocusVisible)
|
|
505
505
|
;
|
|
@@ -508,17 +508,17 @@ function $e63d024ca16f2165$export$4e328f61c538687f(props = {
|
|
|
508
508
|
setFocused(isFocused);
|
|
509
509
|
updateState();
|
|
510
510
|
};
|
|
511
|
-
$
|
|
511
|
+
$6nfFC$useFocusVisibleListener((isFocusVisible)=>{
|
|
512
512
|
state.isFocusVisible = isFocusVisible;
|
|
513
513
|
updateState();
|
|
514
514
|
}, [], {
|
|
515
515
|
isTextInput: isTextInput
|
|
516
516
|
});
|
|
517
|
-
let { focusProps: focusProps } = $
|
|
517
|
+
let { focusProps: focusProps } = $6nfFC$useFocus({
|
|
518
518
|
isDisabled: within,
|
|
519
519
|
onFocusChange: onFocusChange
|
|
520
520
|
});
|
|
521
|
-
let { focusWithinProps: focusWithinProps } = $
|
|
521
|
+
let { focusWithinProps: focusWithinProps } = $6nfFC$useFocusWithin({
|
|
522
522
|
isDisabled: !within,
|
|
523
523
|
onFocusWithinChange: onFocusChange
|
|
524
524
|
});
|
|
@@ -530,13 +530,13 @@ function $e63d024ca16f2165$export$4e328f61c538687f(props = {
|
|
|
530
530
|
}
|
|
531
531
|
|
|
532
532
|
|
|
533
|
-
function $
|
|
533
|
+
function $907718708eab68af$export$1a38b4ad7f578e1d(props) {
|
|
534
534
|
let { children: children , focusClass: focusClass , focusRingClass: focusRingClass } = props;
|
|
535
|
-
let { isFocused: isFocused , isFocusVisible: isFocusVisible , focusProps: focusProps } = $
|
|
536
|
-
let child = $
|
|
537
|
-
return(/*#__PURE__*/ $
|
|
535
|
+
let { isFocused: isFocused , isFocusVisible: isFocusVisible , focusProps: focusProps } = $f7dceffc5ad7768b$export$4e328f61c538687f(props);
|
|
536
|
+
let child = $6nfFC$react.Children.only(children);
|
|
537
|
+
return(/*#__PURE__*/ $6nfFC$react.cloneElement(child, $6nfFC$mergeProps(child.props, {
|
|
538
538
|
...focusProps,
|
|
539
|
-
className: $
|
|
539
|
+
className: $6nfFC$clsx({
|
|
540
540
|
[focusClass || '']: isFocused,
|
|
541
541
|
[focusRingClass || '']: isFocusVisible
|
|
542
542
|
})
|
|
@@ -544,49 +544,52 @@ function $503734efc0922182$export$1a38b4ad7f578e1d(props) {
|
|
|
544
544
|
}
|
|
545
545
|
|
|
546
546
|
|
|
547
|
-
var $
|
|
547
|
+
var $e6afbd83fe6ebbd2$exports = {};
|
|
548
548
|
|
|
549
|
-
$parcel$export($
|
|
550
|
-
$parcel$export($
|
|
549
|
+
$parcel$export($e6afbd83fe6ebbd2$exports, "FocusableProvider", () => $e6afbd83fe6ebbd2$export$13f3202a3e5ddd5);
|
|
550
|
+
$parcel$export($e6afbd83fe6ebbd2$exports, "useFocusable", () => $e6afbd83fe6ebbd2$export$4c014de7c8940b4c);
|
|
551
551
|
|
|
552
552
|
|
|
553
553
|
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
554
|
+
|
|
555
|
+
let $e6afbd83fe6ebbd2$var$FocusableContext = /*#__PURE__*/ $6nfFC$react.createContext(null);
|
|
556
|
+
function $e6afbd83fe6ebbd2$var$useFocusableContext(ref) {
|
|
557
|
+
let context = $6nfFC$useContext($e6afbd83fe6ebbd2$var$FocusableContext) || {
|
|
557
558
|
};
|
|
558
|
-
$
|
|
559
|
+
$6nfFC$useSyncRef(context, ref);
|
|
559
560
|
// eslint-disable-next-line
|
|
560
561
|
let { ref: _ , ...otherProps } = context;
|
|
561
562
|
return otherProps;
|
|
562
563
|
}
|
|
563
564
|
/**
|
|
564
565
|
* Provides DOM props to the nearest focusable child.
|
|
565
|
-
*/ function $
|
|
566
|
+
*/ function $e6afbd83fe6ebbd2$var$FocusableProvider(props, ref) {
|
|
566
567
|
let { children: children , ...otherProps } = props;
|
|
567
568
|
let context = {
|
|
568
569
|
...otherProps,
|
|
569
570
|
ref: ref
|
|
570
571
|
};
|
|
571
|
-
return(/*#__PURE__*/ $
|
|
572
|
+
return(/*#__PURE__*/ $6nfFC$react.createElement($e6afbd83fe6ebbd2$var$FocusableContext.Provider, {
|
|
572
573
|
value: context
|
|
573
574
|
}, children));
|
|
574
575
|
}
|
|
575
|
-
let $
|
|
576
|
-
function $
|
|
577
|
-
let { focusProps: focusProps } = $
|
|
578
|
-
let { keyboardProps: keyboardProps } = $
|
|
579
|
-
let interactions = $
|
|
580
|
-
let domProps = $
|
|
576
|
+
let $e6afbd83fe6ebbd2$export$13f3202a3e5ddd5 = /*#__PURE__*/ $6nfFC$react.forwardRef($e6afbd83fe6ebbd2$var$FocusableProvider);
|
|
577
|
+
function $e6afbd83fe6ebbd2$export$4c014de7c8940b4c(props, domRef) {
|
|
578
|
+
let { focusProps: focusProps } = $6nfFC$useFocus(props);
|
|
579
|
+
let { keyboardProps: keyboardProps } = $6nfFC$useKeyboard(props);
|
|
580
|
+
let interactions = $6nfFC$mergeProps(focusProps, keyboardProps);
|
|
581
|
+
let domProps = $e6afbd83fe6ebbd2$var$useFocusableContext(domRef);
|
|
581
582
|
let interactionProps = props.isDisabled ? {
|
|
582
583
|
} : domProps;
|
|
583
|
-
let autoFocusRef = $
|
|
584
|
-
$
|
|
585
|
-
if (autoFocusRef.current && domRef.current) domRef.current
|
|
584
|
+
let autoFocusRef = $6nfFC$useRef(props.autoFocus);
|
|
585
|
+
$6nfFC$useEffect(()=>{
|
|
586
|
+
if (autoFocusRef.current && domRef.current) $6a99195332edec8b$export$80f3e147d781571c(domRef.current);
|
|
586
587
|
autoFocusRef.current = false;
|
|
587
|
-
}, [
|
|
588
|
+
}, [
|
|
589
|
+
domRef
|
|
590
|
+
]);
|
|
588
591
|
return {
|
|
589
|
-
focusableProps: $
|
|
592
|
+
focusableProps: $6nfFC$mergeProps({
|
|
590
593
|
...interactions,
|
|
591
594
|
tabIndex: props.excludeFromTabOrder && !props.isDisabled ? -1 : undefined
|
|
592
595
|
}, interactionProps)
|
|
@@ -598,5 +601,5 @@ function $391c6482f25a1991$export$4c014de7c8940b4c(props, domRef) {
|
|
|
598
601
|
|
|
599
602
|
|
|
600
603
|
|
|
601
|
-
export {$
|
|
604
|
+
export {$9bf71ea28793e738$export$20e40289641fbbb6 as FocusScope, $9bf71ea28793e738$export$10c5169755ce7bd7 as useFocusManager, $9bf71ea28793e738$export$2d6ec8fc375ceafa as getFocusableTreeWalker, $9bf71ea28793e738$export$c5251b9e124bf29 as createFocusManager, $907718708eab68af$export$1a38b4ad7f578e1d as FocusRing, $e6afbd83fe6ebbd2$export$13f3202a3e5ddd5 as FocusableProvider, $e6afbd83fe6ebbd2$export$4c014de7c8940b4c as useFocusable, $f7dceffc5ad7768b$export$4e328f61c538687f as useFocusRing, $6a99195332edec8b$export$80f3e147d781571c as focusSafely};
|
|
602
605
|
//# sourceMappingURL=module.js.map
|