@react-aria/focus 3.10.0 → 3.11.0
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/import.mjs +861 -0
- package/dist/main.js +241 -175
- package/dist/main.js.map +1 -1
- package/dist/module.js +241 -175
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +11 -6
- package/src/FocusScope.tsx +74 -28
package/dist/main.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
var $aB6Cp$swchelperslib_define_propertyjs = require("@swc/helpers/lib/_define_property.js");
|
|
1
2
|
var $aB6Cp$react = require("react");
|
|
2
3
|
var $aB6Cp$reactariautils = require("@react-aria/utils");
|
|
3
4
|
var $aB6Cp$reactariainteractions = require("@react-aria/interactions");
|
|
@@ -20,7 +21,38 @@ $parcel$export(module.exports, "FocusableProvider", () => $fb504d83237fd6ac$expo
|
|
|
20
21
|
$parcel$export(module.exports, "useFocusable", () => $fb504d83237fd6ac$export$4c014de7c8940b4c);
|
|
21
22
|
$parcel$export(module.exports, "useFocusRing", () => $581a96d6eb128c1b$export$4e328f61c538687f);
|
|
22
23
|
$parcel$export(module.exports, "focusSafely", () => $1c7f9157d722357d$export$80f3e147d781571c);
|
|
23
|
-
|
|
24
|
+
/*
|
|
25
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
26
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
27
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
28
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
29
|
+
*
|
|
30
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
31
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
32
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
33
|
+
* governing permissions and limitations under the License.
|
|
34
|
+
*/ /*
|
|
35
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
36
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
37
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
38
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
39
|
+
*
|
|
40
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
41
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
42
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
43
|
+
* governing permissions and limitations under the License.
|
|
44
|
+
*/
|
|
45
|
+
/*
|
|
46
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
47
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the 'License');
|
|
48
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
49
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
50
|
+
*
|
|
51
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
52
|
+
* the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
53
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
54
|
+
* governing permissions and limitations under the License.
|
|
55
|
+
*/
|
|
24
56
|
|
|
25
57
|
function $1c7f9157d722357d$export$80f3e147d781571c(element) {
|
|
26
58
|
// If the user is interacting with a virtual cursor, e.g. screen reader, then
|
|
@@ -28,13 +60,13 @@ function $1c7f9157d722357d$export$80f3e147d781571c(element) {
|
|
|
28
60
|
// the page before shifting focus. This avoids issues with VoiceOver on iOS
|
|
29
61
|
// causing the page to scroll when moving focus if the element is transitioning
|
|
30
62
|
// from off the screen.
|
|
31
|
-
if ($aB6Cp$reactariainteractions.getInteractionModality() ===
|
|
63
|
+
if ((0, $aB6Cp$reactariainteractions.getInteractionModality)() === "virtual") {
|
|
32
64
|
let lastFocusedElement = document.activeElement;
|
|
33
|
-
$aB6Cp$reactariautils.runAfterTransition(()=>{
|
|
65
|
+
(0, $aB6Cp$reactariautils.runAfterTransition)(()=>{
|
|
34
66
|
// If focus did not move and the element is still in the document, focus it.
|
|
35
|
-
if (document.activeElement === lastFocusedElement && document.contains(element)) $aB6Cp$reactariautils.focusWithoutScrolling(element);
|
|
67
|
+
if (document.activeElement === lastFocusedElement && document.contains(element)) (0, $aB6Cp$reactariautils.focusWithoutScrolling)(element);
|
|
36
68
|
});
|
|
37
|
-
} else $aB6Cp$reactariautils.focusWithoutScrolling(element);
|
|
69
|
+
} else (0, $aB6Cp$reactariautils.focusWithoutScrolling)(element);
|
|
38
70
|
}
|
|
39
71
|
|
|
40
72
|
|
|
@@ -51,42 +83,62 @@ function $1c7f9157d722357d$export$80f3e147d781571c(element) {
|
|
|
51
83
|
*/ function $d5156037ad898a4d$var$isStyleVisible(element) {
|
|
52
84
|
if (!(element instanceof HTMLElement) && !(element instanceof SVGElement)) return false;
|
|
53
85
|
let { display: display , visibility: visibility } = element.style;
|
|
54
|
-
let isVisible = display !==
|
|
86
|
+
let isVisible = display !== "none" && visibility !== "hidden" && visibility !== "collapse";
|
|
55
87
|
if (isVisible) {
|
|
56
88
|
const { getComputedStyle: getComputedStyle } = element.ownerDocument.defaultView;
|
|
57
89
|
let { display: computedDisplay , visibility: computedVisibility } = getComputedStyle(element);
|
|
58
|
-
isVisible = computedDisplay !==
|
|
90
|
+
isVisible = computedDisplay !== "none" && computedVisibility !== "hidden" && computedVisibility !== "collapse";
|
|
59
91
|
}
|
|
60
92
|
return isVisible;
|
|
61
93
|
}
|
|
62
94
|
function $d5156037ad898a4d$var$isAttributeVisible(element, childElement) {
|
|
63
|
-
return !element.hasAttribute(
|
|
95
|
+
return !element.hasAttribute("hidden") && (element.nodeName === "DETAILS" && childElement && childElement.nodeName !== "SUMMARY" ? element.hasAttribute("open") : true);
|
|
64
96
|
}
|
|
65
97
|
function $d5156037ad898a4d$export$e989c0fffaa6b27a(element, childElement) {
|
|
66
|
-
return element.nodeName !==
|
|
98
|
+
return element.nodeName !== "#comment" && $d5156037ad898a4d$var$isStyleVisible(element) && $d5156037ad898a4d$var$isAttributeVisible(element, childElement) && (!element.parentElement || $d5156037ad898a4d$export$e989c0fffaa6b27a(element.parentElement, element));
|
|
67
99
|
}
|
|
68
100
|
|
|
69
101
|
|
|
70
102
|
|
|
71
103
|
|
|
72
|
-
const $a7a032acae3ddda9$var$FocusContext = /*#__PURE__*/ ($parcel$interopDefault($aB6Cp$react)).createContext(null);
|
|
104
|
+
const $a7a032acae3ddda9$var$FocusContext = /*#__PURE__*/ (0, ($parcel$interopDefault($aB6Cp$react))).createContext(null);
|
|
73
105
|
let $a7a032acae3ddda9$var$activeScope = null;
|
|
74
106
|
function $a7a032acae3ddda9$export$20e40289641fbbb6(props) {
|
|
75
107
|
let { children: children , contain: contain , restoreFocus: restoreFocus , autoFocus: autoFocus } = props;
|
|
76
|
-
let startRef = $aB6Cp$react.useRef();
|
|
77
|
-
let endRef = $aB6Cp$react.useRef();
|
|
78
|
-
let scopeRef = $aB6Cp$react.useRef([]);
|
|
79
|
-
let
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
,
|
|
87
|
-
|
|
108
|
+
let startRef = (0, $aB6Cp$react.useRef)();
|
|
109
|
+
let endRef = (0, $aB6Cp$react.useRef)();
|
|
110
|
+
let scopeRef = (0, $aB6Cp$react.useRef)([]);
|
|
111
|
+
let { parentNode: parentNode } = (0, $aB6Cp$react.useContext)($a7a032acae3ddda9$var$FocusContext) || {};
|
|
112
|
+
// Create a tree node here so we can add children to it even before it is added to the tree.
|
|
113
|
+
let node = (0, $aB6Cp$react.useMemo)(()=>new $a7a032acae3ddda9$var$TreeNode({
|
|
114
|
+
scopeRef: scopeRef
|
|
115
|
+
}), [
|
|
116
|
+
scopeRef
|
|
117
|
+
]);
|
|
118
|
+
(0, $aB6Cp$reactariautils.useLayoutEffect)(()=>{
|
|
119
|
+
// If a new scope mounts outside the active scope, (e.g. DialogContainer launched from a menu),
|
|
120
|
+
// use the active scope as the parent instead of the parent from context. Layout effects run bottom
|
|
121
|
+
// up, so if the parent is not yet added to the tree, don't do this. Only the outer-most FocusScope
|
|
122
|
+
// that is being added should get the activeScope as its parent.
|
|
123
|
+
let parent = parentNode || $a7a032acae3ddda9$export$d06fae2ee68b101e.root;
|
|
124
|
+
if ($a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(parent.scopeRef) && $a7a032acae3ddda9$var$activeScope && !$a7a032acae3ddda9$var$isAncestorScope($a7a032acae3ddda9$var$activeScope, parent.scopeRef)) {
|
|
125
|
+
let activeNode = $a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode($a7a032acae3ddda9$var$activeScope);
|
|
126
|
+
if (activeNode) parent = activeNode;
|
|
127
|
+
}
|
|
128
|
+
// Add the node to the parent, and to the tree.
|
|
129
|
+
parent.addChild(node);
|
|
130
|
+
$a7a032acae3ddda9$export$d06fae2ee68b101e.addNode(node);
|
|
131
|
+
}, [
|
|
132
|
+
node,
|
|
133
|
+
parentNode
|
|
134
|
+
]);
|
|
135
|
+
(0, $aB6Cp$reactariautils.useLayoutEffect)(()=>{
|
|
136
|
+
let node = $a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(scopeRef);
|
|
137
|
+
node.contain = contain;
|
|
138
|
+
}, [
|
|
139
|
+
contain
|
|
88
140
|
]);
|
|
89
|
-
$aB6Cp$reactariautils.useLayoutEffect(()=>{
|
|
141
|
+
(0, $aB6Cp$reactariautils.useLayoutEffect)(()=>{
|
|
90
142
|
// Find all rendered nodes between the sentinels and add them to the scope.
|
|
91
143
|
let node = startRef.current.nextSibling;
|
|
92
144
|
let nodes = [];
|
|
@@ -96,57 +148,65 @@ function $a7a032acae3ddda9$export$20e40289641fbbb6(props) {
|
|
|
96
148
|
}
|
|
97
149
|
scopeRef.current = nodes;
|
|
98
150
|
}, [
|
|
99
|
-
children
|
|
100
|
-
parentScope1
|
|
151
|
+
children
|
|
101
152
|
]);
|
|
102
|
-
// add to the focus scope tree in render order because useEffects/useLayoutEffects run children first whereas render runs parent first
|
|
103
|
-
// which matters when constructing a tree
|
|
104
|
-
if ($a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(parentScope1) && !$a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(scopeRef)) $a7a032acae3ddda9$export$d06fae2ee68b101e.addTreeNode(scopeRef, parentScope1);
|
|
105
|
-
let node1 = $a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(scopeRef);
|
|
106
|
-
node1.contain = contain;
|
|
107
153
|
$a7a032acae3ddda9$var$useActiveScopeTracker(scopeRef, restoreFocus, contain);
|
|
108
154
|
$a7a032acae3ddda9$var$useFocusContainment(scopeRef, contain);
|
|
109
155
|
$a7a032acae3ddda9$var$useRestoreFocus(scopeRef, restoreFocus, contain);
|
|
110
156
|
$a7a032acae3ddda9$var$useAutoFocus(scopeRef, autoFocus);
|
|
111
157
|
// this layout effect needs to run last so that focusScopeTree cleanup happens at the last moment possible
|
|
112
|
-
$aB6Cp$
|
|
113
|
-
if (scopeRef)
|
|
114
|
-
|
|
115
|
-
let
|
|
116
|
-
//
|
|
117
|
-
//
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
158
|
+
(0, $aB6Cp$react.useEffect)(()=>{
|
|
159
|
+
if (scopeRef) {
|
|
160
|
+
let activeElement = document.activeElement;
|
|
161
|
+
let scope = null;
|
|
162
|
+
// In strict mode, active scope is incorrectly updated since cleanup will run even though scope hasn't unmounted.
|
|
163
|
+
// To fix this, we need to update the actual activeScope here
|
|
164
|
+
if ($a7a032acae3ddda9$var$isElementInScope(activeElement, scopeRef.current)) {
|
|
165
|
+
// Since useLayoutEffect runs for children first, we need to traverse the focusScope tree and find the bottom most scope that
|
|
166
|
+
// contains the active element and set that as the activeScope
|
|
167
|
+
for (let node of $a7a032acae3ddda9$export$d06fae2ee68b101e.traverse())if ($a7a032acae3ddda9$var$isElementInScope(activeElement, node.scopeRef.current)) scope = node;
|
|
168
|
+
if (scope === $a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(scopeRef)) $a7a032acae3ddda9$var$activeScope = scope.scopeRef;
|
|
169
|
+
}
|
|
170
|
+
return ()=>{
|
|
171
|
+
// Scope may have been re-parented.
|
|
172
|
+
let parentScope = $a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(scopeRef).parent.scopeRef;
|
|
173
|
+
// Restore the active scope on unmount if this scope or a descendant scope is active.
|
|
174
|
+
// Parent effect cleanups run before children, so we need to check if the
|
|
175
|
+
// parent scope actually still exists before restoring the active scope to it.
|
|
176
|
+
if ((scopeRef === $a7a032acae3ddda9$var$activeScope || $a7a032acae3ddda9$var$isAncestorScope(scopeRef, $a7a032acae3ddda9$var$activeScope)) && (!parentScope || $a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(parentScope))) $a7a032acae3ddda9$var$activeScope = parentScope;
|
|
177
|
+
$a7a032acae3ddda9$export$d06fae2ee68b101e.removeTreeNode(scopeRef);
|
|
178
|
+
};
|
|
179
|
+
}
|
|
122
180
|
}, [
|
|
123
|
-
scopeRef
|
|
124
|
-
parentScope1
|
|
181
|
+
scopeRef
|
|
125
182
|
]);
|
|
126
|
-
let focusManager = $a7a032acae3ddda9$var$createFocusManagerForScope(scopeRef);
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
183
|
+
let focusManager = (0, $aB6Cp$react.useMemo)(()=>$a7a032acae3ddda9$var$createFocusManagerForScope(scopeRef), []);
|
|
184
|
+
let value = (0, $aB6Cp$react.useMemo)(()=>({
|
|
185
|
+
focusManager: focusManager,
|
|
186
|
+
parentNode: node
|
|
187
|
+
}), [
|
|
188
|
+
node,
|
|
189
|
+
focusManager
|
|
190
|
+
]);
|
|
191
|
+
return /*#__PURE__*/ (0, ($parcel$interopDefault($aB6Cp$react))).createElement($a7a032acae3ddda9$var$FocusContext.Provider, {
|
|
192
|
+
value: value
|
|
193
|
+
}, /*#__PURE__*/ (0, ($parcel$interopDefault($aB6Cp$react))).createElement("span", {
|
|
133
194
|
"data-focus-scope-start": true,
|
|
134
195
|
hidden: true,
|
|
135
196
|
ref: startRef
|
|
136
|
-
}), children, /*#__PURE__*/ ($parcel$interopDefault($aB6Cp$react)).createElement("span", {
|
|
197
|
+
}), children, /*#__PURE__*/ (0, ($parcel$interopDefault($aB6Cp$react))).createElement("span", {
|
|
137
198
|
"data-focus-scope-end": true,
|
|
138
199
|
hidden: true,
|
|
139
200
|
ref: endRef
|
|
140
|
-
}))
|
|
201
|
+
}));
|
|
141
202
|
}
|
|
142
203
|
function $a7a032acae3ddda9$export$10c5169755ce7bd7() {
|
|
143
|
-
var
|
|
144
|
-
return (
|
|
204
|
+
var _useContext;
|
|
205
|
+
return (_useContext = (0, $aB6Cp$react.useContext)($a7a032acae3ddda9$var$FocusContext)) === null || _useContext === void 0 ? void 0 : _useContext.focusManager;
|
|
145
206
|
}
|
|
146
207
|
function $a7a032acae3ddda9$var$createFocusManagerForScope(scopeRef) {
|
|
147
208
|
return {
|
|
148
|
-
focusNext (opts = {
|
|
149
|
-
}) {
|
|
209
|
+
focusNext (opts = {}) {
|
|
150
210
|
let scope = scopeRef.current;
|
|
151
211
|
let { from: from , tabbable: tabbable , wrap: wrap , accept: accept } = opts;
|
|
152
212
|
let node = from || document.activeElement;
|
|
@@ -164,8 +224,7 @@ function $a7a032acae3ddda9$var$createFocusManagerForScope(scopeRef) {
|
|
|
164
224
|
if (nextNode) $a7a032acae3ddda9$var$focusElement(nextNode, true);
|
|
165
225
|
return nextNode;
|
|
166
226
|
},
|
|
167
|
-
focusPrevious (opts = {
|
|
168
|
-
}) {
|
|
227
|
+
focusPrevious (opts = {}) {
|
|
169
228
|
let scope = scopeRef.current;
|
|
170
229
|
let { from: from , tabbable: tabbable , wrap: wrap , accept: accept } = opts;
|
|
171
230
|
let node = from || document.activeElement;
|
|
@@ -183,8 +242,7 @@ function $a7a032acae3ddda9$var$createFocusManagerForScope(scopeRef) {
|
|
|
183
242
|
if (previousNode) $a7a032acae3ddda9$var$focusElement(previousNode, true);
|
|
184
243
|
return previousNode;
|
|
185
244
|
},
|
|
186
|
-
focusFirst (opts = {
|
|
187
|
-
}) {
|
|
245
|
+
focusFirst (opts = {}) {
|
|
188
246
|
let scope = scopeRef.current;
|
|
189
247
|
let { tabbable: tabbable , accept: accept } = opts;
|
|
190
248
|
let walker = $a7a032acae3ddda9$export$2d6ec8fc375ceafa($a7a032acae3ddda9$var$getScopeRoot(scope), {
|
|
@@ -196,8 +254,7 @@ function $a7a032acae3ddda9$var$createFocusManagerForScope(scopeRef) {
|
|
|
196
254
|
if (nextNode) $a7a032acae3ddda9$var$focusElement(nextNode, true);
|
|
197
255
|
return nextNode;
|
|
198
256
|
},
|
|
199
|
-
focusLast (opts = {
|
|
200
|
-
}) {
|
|
257
|
+
focusLast (opts = {}) {
|
|
201
258
|
let scope = scopeRef.current;
|
|
202
259
|
let { tabbable: tabbable , accept: accept } = opts;
|
|
203
260
|
let walker = $a7a032acae3ddda9$export$2d6ec8fc375ceafa($a7a032acae3ddda9$var$getScopeRoot(scope), {
|
|
@@ -212,21 +269,21 @@ function $a7a032acae3ddda9$var$createFocusManagerForScope(scopeRef) {
|
|
|
212
269
|
};
|
|
213
270
|
}
|
|
214
271
|
const $a7a032acae3ddda9$var$focusableElements = [
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
272
|
+
"input:not([disabled]):not([type=hidden])",
|
|
273
|
+
"select:not([disabled])",
|
|
274
|
+
"textarea:not([disabled])",
|
|
275
|
+
"button:not([disabled])",
|
|
276
|
+
"a[href]",
|
|
277
|
+
"area[href]",
|
|
278
|
+
"summary",
|
|
279
|
+
"iframe",
|
|
280
|
+
"object",
|
|
281
|
+
"embed",
|
|
282
|
+
"audio[controls]",
|
|
283
|
+
"video[controls]",
|
|
284
|
+
"[contenteditable]"
|
|
228
285
|
];
|
|
229
|
-
const $a7a032acae3ddda9$var$FOCUSABLE_ELEMENT_SELECTOR = $a7a032acae3ddda9$var$focusableElements.join(
|
|
286
|
+
const $a7a032acae3ddda9$var$FOCUSABLE_ELEMENT_SELECTOR = $a7a032acae3ddda9$var$focusableElements.join(":not([hidden]),") + ",[tabindex]:not([disabled]):not([hidden])";
|
|
230
287
|
$a7a032acae3ddda9$var$focusableElements.push('[tabindex]:not([tabindex="-1"]):not([disabled])');
|
|
231
288
|
const $a7a032acae3ddda9$var$TABBABLE_ELEMENT_SELECTOR = $a7a032acae3ddda9$var$focusableElements.join(':not([hidden]):not([tabindex="-1"]),');
|
|
232
289
|
function $a7a032acae3ddda9$var$getScopeRoot(scope) {
|
|
@@ -241,10 +298,10 @@ function $a7a032acae3ddda9$var$shouldContainFocus(scopeRef) {
|
|
|
241
298
|
return true;
|
|
242
299
|
}
|
|
243
300
|
function $a7a032acae3ddda9$var$useFocusContainment(scopeRef, contain) {
|
|
244
|
-
let focusedNode = $aB6Cp$react.useRef();
|
|
245
|
-
let raf = $aB6Cp$react.useRef(null);
|
|
246
|
-
$aB6Cp$reactariautils.useLayoutEffect(()=>{
|
|
247
|
-
let
|
|
301
|
+
let focusedNode = (0, $aB6Cp$react.useRef)();
|
|
302
|
+
let raf = (0, $aB6Cp$react.useRef)(null);
|
|
303
|
+
(0, $aB6Cp$reactariautils.useLayoutEffect)(()=>{
|
|
304
|
+
let scope = scopeRef.current;
|
|
248
305
|
if (!contain) {
|
|
249
306
|
// if contain was changed, then we should cancel any ongoing waits to pull focus back into containment
|
|
250
307
|
if (raf.current) {
|
|
@@ -255,7 +312,7 @@ function $a7a032acae3ddda9$var$useFocusContainment(scopeRef, contain) {
|
|
|
255
312
|
}
|
|
256
313
|
// Handle the Tab key to contain focus within the scope
|
|
257
314
|
let onKeyDown = (e)=>{
|
|
258
|
-
if (e.key !==
|
|
315
|
+
if (e.key !== "Tab" || e.altKey || e.ctrlKey || e.metaKey || !$a7a032acae3ddda9$var$shouldContainFocus(scopeRef)) return;
|
|
259
316
|
let focusedElement = document.activeElement;
|
|
260
317
|
let scope = scopeRef.current;
|
|
261
318
|
if (!$a7a032acae3ddda9$var$isElementInScope(focusedElement, scope)) return;
|
|
@@ -286,6 +343,7 @@ function $a7a032acae3ddda9$var$useFocusContainment(scopeRef, contain) {
|
|
|
286
343
|
};
|
|
287
344
|
let onBlur = (e)=>{
|
|
288
345
|
// Firefox doesn't shift focus back to the Dialog properly without this
|
|
346
|
+
if (raf.current) cancelAnimationFrame(raf.current);
|
|
289
347
|
raf.current = requestAnimationFrame(()=>{
|
|
290
348
|
// Use document.activeElement instead of e.relatedTarget so we can tell if user clicked into iframe
|
|
291
349
|
if ($a7a032acae3ddda9$var$shouldContainFocus(scopeRef) && !$a7a032acae3ddda9$var$isElementInChildScope(document.activeElement, scopeRef)) {
|
|
@@ -297,26 +355,22 @@ function $a7a032acae3ddda9$var$useFocusContainment(scopeRef, contain) {
|
|
|
297
355
|
}
|
|
298
356
|
});
|
|
299
357
|
};
|
|
300
|
-
document.addEventListener(
|
|
301
|
-
document.addEventListener(
|
|
302
|
-
|
|
303
|
-
);
|
|
304
|
-
scope1.forEach((element)=>element.addEventListener('focusout', onBlur, false)
|
|
305
|
-
);
|
|
358
|
+
document.addEventListener("keydown", onKeyDown, false);
|
|
359
|
+
document.addEventListener("focusin", onFocus, false);
|
|
360
|
+
scope.forEach((element)=>element.addEventListener("focusin", onFocus, false));
|
|
361
|
+
scope.forEach((element)=>element.addEventListener("focusout", onBlur, false));
|
|
306
362
|
return ()=>{
|
|
307
|
-
document.removeEventListener(
|
|
308
|
-
document.removeEventListener(
|
|
309
|
-
|
|
310
|
-
);
|
|
311
|
-
scope1.forEach((element)=>element.removeEventListener('focusout', onBlur, false)
|
|
312
|
-
);
|
|
363
|
+
document.removeEventListener("keydown", onKeyDown, false);
|
|
364
|
+
document.removeEventListener("focusin", onFocus, false);
|
|
365
|
+
scope.forEach((element)=>element.removeEventListener("focusin", onFocus, false));
|
|
366
|
+
scope.forEach((element)=>element.removeEventListener("focusout", onBlur, false));
|
|
313
367
|
};
|
|
314
368
|
}, [
|
|
315
369
|
scopeRef,
|
|
316
370
|
contain
|
|
317
371
|
]);
|
|
318
372
|
// eslint-disable-next-line arrow-body-style
|
|
319
|
-
$aB6Cp$react.useEffect(()=>{
|
|
373
|
+
(0, $aB6Cp$react.useEffect)(()=>{
|
|
320
374
|
return ()=>{
|
|
321
375
|
if (raf.current) cancelAnimationFrame(raf.current);
|
|
322
376
|
};
|
|
@@ -328,10 +382,11 @@ function $a7a032acae3ddda9$var$isElementInAnyScope(element) {
|
|
|
328
382
|
return $a7a032acae3ddda9$var$isElementInChildScope(element);
|
|
329
383
|
}
|
|
330
384
|
function $a7a032acae3ddda9$var$isElementInScope(element, scope) {
|
|
331
|
-
return scope.some((node)=>node.contains(element)
|
|
332
|
-
);
|
|
385
|
+
return scope.some((node)=>node.contains(element));
|
|
333
386
|
}
|
|
334
387
|
function $a7a032acae3ddda9$var$isElementInChildScope(element, scope = null) {
|
|
388
|
+
// If the element is within a top layer element (e.g. toasts), always allow moving focus there.
|
|
389
|
+
if (element instanceof Element && element.closest("[data-react-aria-top-layer]")) return true;
|
|
335
390
|
// node.contains in isElementInScope covers child scopes that are also DOM children,
|
|
336
391
|
// but does not cover child scopes in portals.
|
|
337
392
|
for (let { scopeRef: s } of $a7a032acae3ddda9$export$d06fae2ee68b101e.traverse($a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(scope))){
|
|
@@ -343,8 +398,8 @@ function $a7a032acae3ddda9$export$1258395f99bf9cbf(element) {
|
|
|
343
398
|
return $a7a032acae3ddda9$var$isElementInChildScope(element, $a7a032acae3ddda9$var$activeScope);
|
|
344
399
|
}
|
|
345
400
|
function $a7a032acae3ddda9$var$isAncestorScope(ancestor, scope) {
|
|
346
|
-
var
|
|
347
|
-
let parent = (
|
|
401
|
+
var _focusScopeTree_getTreeNode;
|
|
402
|
+
let parent = (_focusScopeTree_getTreeNode = $a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(scope)) === null || _focusScopeTree_getTreeNode === void 0 ? void 0 : _focusScopeTree_getTreeNode.parent;
|
|
348
403
|
while(parent){
|
|
349
404
|
if (parent.scopeRef === ancestor) return true;
|
|
350
405
|
parent = parent.parent;
|
|
@@ -353,7 +408,7 @@ function $a7a032acae3ddda9$var$isAncestorScope(ancestor, scope) {
|
|
|
353
408
|
}
|
|
354
409
|
function $a7a032acae3ddda9$var$focusElement(element, scroll = false) {
|
|
355
410
|
if (element != null && !scroll) try {
|
|
356
|
-
$1c7f9157d722357d$export$80f3e147d781571c(element);
|
|
411
|
+
(0, $1c7f9157d722357d$export$80f3e147d781571c)(element);
|
|
357
412
|
} catch (err) {
|
|
358
413
|
// ignore
|
|
359
414
|
}
|
|
@@ -381,8 +436,8 @@ function $a7a032acae3ddda9$var$focusFirstInScope(scope, tabbable = true) {
|
|
|
381
436
|
$a7a032acae3ddda9$var$focusElement(nextNode);
|
|
382
437
|
}
|
|
383
438
|
function $a7a032acae3ddda9$var$useAutoFocus(scopeRef, autoFocus) {
|
|
384
|
-
const autoFocusRef = ($parcel$interopDefault($aB6Cp$react)).useRef(autoFocus);
|
|
385
|
-
$aB6Cp$react.useEffect(()=>{
|
|
439
|
+
const autoFocusRef = (0, ($parcel$interopDefault($aB6Cp$react))).useRef(autoFocus);
|
|
440
|
+
(0, $aB6Cp$react.useEffect)(()=>{
|
|
386
441
|
if (autoFocusRef.current) {
|
|
387
442
|
$a7a032acae3ddda9$var$activeScope = scopeRef;
|
|
388
443
|
if (!$a7a032acae3ddda9$var$isElementInScope(document.activeElement, $a7a032acae3ddda9$var$activeScope.current)) $a7a032acae3ddda9$var$focusFirstInScope(scopeRef.current);
|
|
@@ -395,7 +450,7 @@ function $a7a032acae3ddda9$var$useAutoFocus(scopeRef, autoFocus) {
|
|
|
395
450
|
function $a7a032acae3ddda9$var$useActiveScopeTracker(scopeRef, restore, contain) {
|
|
396
451
|
// tracks the active scope, in case restore and contain are both false.
|
|
397
452
|
// if either are true, this is tracked in useRestoreFocus or useFocusContainment.
|
|
398
|
-
$aB6Cp$reactariautils.useLayoutEffect(()=>{
|
|
453
|
+
(0, $aB6Cp$reactariautils.useLayoutEffect)(()=>{
|
|
399
454
|
if (restore || contain) return;
|
|
400
455
|
let scope = scopeRef.current;
|
|
401
456
|
let onFocus = (e)=>{
|
|
@@ -403,13 +458,11 @@ function $a7a032acae3ddda9$var$useActiveScopeTracker(scopeRef, restore, contain)
|
|
|
403
458
|
if ($a7a032acae3ddda9$var$isElementInScope(target, scopeRef.current)) $a7a032acae3ddda9$var$activeScope = scopeRef;
|
|
404
459
|
else if (!$a7a032acae3ddda9$var$isElementInAnyScope(target)) $a7a032acae3ddda9$var$activeScope = null;
|
|
405
460
|
};
|
|
406
|
-
document.addEventListener(
|
|
407
|
-
scope.forEach((element)=>element.addEventListener(
|
|
408
|
-
);
|
|
461
|
+
document.addEventListener("focusin", onFocus, false);
|
|
462
|
+
scope.forEach((element)=>element.addEventListener("focusin", onFocus, false));
|
|
409
463
|
return ()=>{
|
|
410
|
-
document.removeEventListener(
|
|
411
|
-
scope.forEach((element)=>element.removeEventListener(
|
|
412
|
-
);
|
|
464
|
+
document.removeEventListener("focusin", onFocus, false);
|
|
465
|
+
scope.forEach((element)=>element.removeEventListener("focusin", onFocus, false));
|
|
413
466
|
};
|
|
414
467
|
}, [
|
|
415
468
|
scopeRef,
|
|
@@ -427,10 +480,10 @@ function $a7a032acae3ddda9$var$shouldRestoreFocus(scopeRef) {
|
|
|
427
480
|
}
|
|
428
481
|
function $a7a032acae3ddda9$var$useRestoreFocus(scopeRef, restoreFocus, contain) {
|
|
429
482
|
// create a ref during render instead of useLayoutEffect so the active element is saved before a child with autoFocus=true mounts.
|
|
430
|
-
const nodeToRestoreRef = $aB6Cp$react.useRef(typeof document !==
|
|
483
|
+
const nodeToRestoreRef = (0, $aB6Cp$react.useRef)(typeof document !== "undefined" ? document.activeElement : null);
|
|
431
484
|
// restoring scopes should all track if they are active regardless of contain, but contain already tracks it plus logic to contain the focus
|
|
432
485
|
// restoring-non-containing scopes should only care if they become active so they can perform the restore
|
|
433
|
-
$aB6Cp$reactariautils.useLayoutEffect(()=>{
|
|
486
|
+
(0, $aB6Cp$reactariautils.useLayoutEffect)(()=>{
|
|
434
487
|
let scope = scopeRef.current;
|
|
435
488
|
if (!restoreFocus || contain) return;
|
|
436
489
|
let onFocus = ()=>{
|
|
@@ -438,13 +491,11 @@ function $a7a032acae3ddda9$var$useRestoreFocus(scopeRef, restoreFocus, contain)
|
|
|
438
491
|
// Moving out of the active scope to an ancestor is not allowed.
|
|
439
492
|
if (!$a7a032acae3ddda9$var$activeScope || $a7a032acae3ddda9$var$isAncestorScope($a7a032acae3ddda9$var$activeScope, scopeRef)) $a7a032acae3ddda9$var$activeScope = scopeRef;
|
|
440
493
|
};
|
|
441
|
-
document.addEventListener(
|
|
442
|
-
scope.forEach((element)=>element.addEventListener(
|
|
443
|
-
);
|
|
494
|
+
document.addEventListener("focusin", onFocus, false);
|
|
495
|
+
scope.forEach((element)=>element.addEventListener("focusin", onFocus, false));
|
|
444
496
|
return ()=>{
|
|
445
|
-
document.removeEventListener(
|
|
446
|
-
scope.forEach((element)=>element.removeEventListener(
|
|
447
|
-
);
|
|
497
|
+
document.removeEventListener("focusin", onFocus, false);
|
|
498
|
+
scope.forEach((element)=>element.removeEventListener("focusin", onFocus, false));
|
|
448
499
|
};
|
|
449
500
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
450
501
|
}, [
|
|
@@ -452,7 +503,7 @@ function $a7a032acae3ddda9$var$useRestoreFocus(scopeRef, restoreFocus, contain)
|
|
|
452
503
|
contain
|
|
453
504
|
]);
|
|
454
505
|
// useLayoutEffect instead of useEffect so the active element is saved synchronously instead of asynchronously.
|
|
455
|
-
$aB6Cp$reactariautils.useLayoutEffect(()=>{
|
|
506
|
+
(0, $aB6Cp$reactariautils.useLayoutEffect)(()=>{
|
|
456
507
|
if (!restoreFocus) return;
|
|
457
508
|
$a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(scopeRef).nodeToRestore = nodeToRestoreRef.current;
|
|
458
509
|
// Handle the Tab key so that tabbing out of the scope goes to the next element
|
|
@@ -460,7 +511,7 @@ function $a7a032acae3ddda9$var$useRestoreFocus(scopeRef, restoreFocus, contain)
|
|
|
460
511
|
// using portals for overlays, so that focus goes to the expected element when
|
|
461
512
|
// tabbing out of the overlay.
|
|
462
513
|
let onKeyDown = (e)=>{
|
|
463
|
-
if (e.key !==
|
|
514
|
+
if (e.key !== "Tab" || e.altKey || e.ctrlKey || e.metaKey) return;
|
|
464
515
|
let focusedElement = document.activeElement;
|
|
465
516
|
if (!$a7a032acae3ddda9$var$isElementInScope(focusedElement, scopeRef.current)) return;
|
|
466
517
|
let nodeToRestore = $a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(scopeRef).nodeToRestore;
|
|
@@ -481,7 +532,7 @@ function $a7a032acae3ddda9$var$useRestoreFocus(scopeRef, restoreFocus, contain)
|
|
|
481
532
|
walker.currentNode = nodeToRestore;
|
|
482
533
|
// Skip over elements within the scope, in case the scope immediately follows the node to restore.
|
|
483
534
|
do nextElement = e.shiftKey ? walker.previousNode() : walker.nextNode();
|
|
484
|
-
while ($a7a032acae3ddda9$var$isElementInScope(nextElement, scopeRef.current))
|
|
535
|
+
while ($a7a032acae3ddda9$var$isElementInScope(nextElement, scopeRef.current));
|
|
485
536
|
e.preventDefault();
|
|
486
537
|
e.stopPropagation();
|
|
487
538
|
if (nextElement) $a7a032acae3ddda9$var$focusElement(nextElement, true);
|
|
@@ -492,9 +543,9 @@ function $a7a032acae3ddda9$var$useRestoreFocus(scopeRef, restoreFocus, contain)
|
|
|
492
543
|
else $a7a032acae3ddda9$var$focusElement(nodeToRestore, true);
|
|
493
544
|
}
|
|
494
545
|
};
|
|
495
|
-
if (!contain) document.addEventListener(
|
|
546
|
+
if (!contain) document.addEventListener("keydown", onKeyDown, true);
|
|
496
547
|
return ()=>{
|
|
497
|
-
if (!contain) document.removeEventListener(
|
|
548
|
+
if (!contain) document.removeEventListener("keydown", onKeyDown, true);
|
|
498
549
|
let nodeToRestore = $a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(scopeRef).nodeToRestore;
|
|
499
550
|
// if we already lost focus to the body and this was the active scope, then we should attempt to restore
|
|
500
551
|
if (restoreFocus && nodeToRestore && // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -537,21 +588,19 @@ function $a7a032acae3ddda9$export$2d6ec8fc375ceafa(root, opts, scope) {
|
|
|
537
588
|
let selector = (opts === null || opts === void 0 ? void 0 : opts.tabbable) ? $a7a032acae3ddda9$var$TABBABLE_ELEMENT_SELECTOR : $a7a032acae3ddda9$var$FOCUSABLE_ELEMENT_SELECTOR;
|
|
538
589
|
let walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, {
|
|
539
590
|
acceptNode (node) {
|
|
540
|
-
var
|
|
591
|
+
var _opts_from;
|
|
541
592
|
// Skip nodes inside the starting node.
|
|
542
|
-
if (opts === null || opts === void 0 ? void 0 : (
|
|
543
|
-
if (node.matches(selector) && $d5156037ad898a4d$export$e989c0fffaa6b27a(node) && (!scope || $a7a032acae3ddda9$var$isElementInScope(node, scope)) && (!(opts === null || opts === void 0 ? void 0 : opts.accept) || opts.accept(node))) return NodeFilter.FILTER_ACCEPT;
|
|
593
|
+
if (opts === null || opts === void 0 ? void 0 : (_opts_from = opts.from) === null || _opts_from === void 0 ? void 0 : _opts_from.contains(node)) return NodeFilter.FILTER_REJECT;
|
|
594
|
+
if (node.matches(selector) && (0, $d5156037ad898a4d$export$e989c0fffaa6b27a)(node) && (!scope || $a7a032acae3ddda9$var$isElementInScope(node, scope)) && (!(opts === null || opts === void 0 ? void 0 : opts.accept) || opts.accept(node))) return NodeFilter.FILTER_ACCEPT;
|
|
544
595
|
return NodeFilter.FILTER_SKIP;
|
|
545
596
|
}
|
|
546
597
|
});
|
|
547
598
|
if (opts === null || opts === void 0 ? void 0 : opts.from) walker.currentNode = opts.from;
|
|
548
599
|
return walker;
|
|
549
600
|
}
|
|
550
|
-
function $a7a032acae3ddda9$export$c5251b9e124bf29(ref, defaultOptions = {
|
|
551
|
-
}) {
|
|
601
|
+
function $a7a032acae3ddda9$export$c5251b9e124bf29(ref, defaultOptions = {}) {
|
|
552
602
|
return {
|
|
553
|
-
focusNext (opts = {
|
|
554
|
-
}) {
|
|
603
|
+
focusNext (opts = {}) {
|
|
555
604
|
let root = ref.current;
|
|
556
605
|
if (!root) return;
|
|
557
606
|
let { from: from , tabbable: tabbable = defaultOptions.tabbable , wrap: wrap = defaultOptions.wrap , accept: accept = defaultOptions.accept } = opts;
|
|
@@ -624,7 +673,7 @@ function $a7a032acae3ddda9$var$last(walker) {
|
|
|
624
673
|
do {
|
|
625
674
|
last = walker.lastChild();
|
|
626
675
|
if (last) next = last;
|
|
627
|
-
}while (last)
|
|
676
|
+
}while (last);
|
|
628
677
|
return next;
|
|
629
678
|
}
|
|
630
679
|
class $a7a032acae3ddda9$var$Tree {
|
|
@@ -644,6 +693,9 @@ class $a7a032acae3ddda9$var$Tree {
|
|
|
644
693
|
this.fastMap.set(scopeRef, node);
|
|
645
694
|
if (nodeToRestore) node.nodeToRestore = nodeToRestore;
|
|
646
695
|
}
|
|
696
|
+
addNode(node) {
|
|
697
|
+
this.fastMap.set(node.scopeRef, node);
|
|
698
|
+
}
|
|
647
699
|
removeTreeNode(scopeRef) {
|
|
648
700
|
// never remove the root
|
|
649
701
|
if (scopeRef === null) return;
|
|
@@ -654,14 +706,13 @@ class $a7a032acae3ddda9$var$Tree {
|
|
|
654
706
|
for (let current of this.traverse())if (current !== node && node.nodeToRestore && current.nodeToRestore && node.scopeRef.current && $a7a032acae3ddda9$var$isElementInScope(current.nodeToRestore, node.scopeRef.current)) current.nodeToRestore = node.nodeToRestore;
|
|
655
707
|
let children = node.children;
|
|
656
708
|
parentNode.removeChild(node);
|
|
657
|
-
if (children.
|
|
658
|
-
);
|
|
709
|
+
if (children.size > 0) children.forEach((child)=>parentNode.addChild(child));
|
|
659
710
|
this.fastMap.delete(node.scopeRef);
|
|
660
711
|
}
|
|
661
712
|
// Pre Order Depth First
|
|
662
713
|
*traverse(node = this.root) {
|
|
663
714
|
if (node.scopeRef != null) yield node;
|
|
664
|
-
if (node.children.
|
|
715
|
+
if (node.children.size > 0) for (let child of node.children)yield* this.traverse(child);
|
|
665
716
|
}
|
|
666
717
|
clone() {
|
|
667
718
|
let newTree = new $a7a032acae3ddda9$var$Tree();
|
|
@@ -669,7 +720,7 @@ class $a7a032acae3ddda9$var$Tree {
|
|
|
669
720
|
return newTree;
|
|
670
721
|
}
|
|
671
722
|
constructor(){
|
|
672
|
-
this
|
|
723
|
+
(0, ($parcel$interopDefault($aB6Cp$swchelperslib_define_propertyjs)))(this, "fastMap", new Map());
|
|
673
724
|
this.root = new $a7a032acae3ddda9$var$TreeNode({
|
|
674
725
|
scopeRef: null
|
|
675
726
|
});
|
|
@@ -678,63 +729,70 @@ class $a7a032acae3ddda9$var$Tree {
|
|
|
678
729
|
}
|
|
679
730
|
class $a7a032acae3ddda9$var$TreeNode {
|
|
680
731
|
addChild(node) {
|
|
681
|
-
this.children.
|
|
732
|
+
this.children.add(node);
|
|
682
733
|
node.parent = this;
|
|
683
734
|
}
|
|
684
735
|
removeChild(node) {
|
|
685
|
-
this.children.
|
|
736
|
+
this.children.delete(node);
|
|
686
737
|
node.parent = undefined;
|
|
687
738
|
}
|
|
688
739
|
constructor(props){
|
|
689
|
-
this
|
|
690
|
-
this
|
|
740
|
+
(0, ($parcel$interopDefault($aB6Cp$swchelperslib_define_propertyjs)))(this, "children", new Set());
|
|
741
|
+
(0, ($parcel$interopDefault($aB6Cp$swchelperslib_define_propertyjs)))(this, "contain", false);
|
|
691
742
|
this.scopeRef = props.scopeRef;
|
|
692
743
|
}
|
|
693
744
|
}
|
|
694
745
|
let $a7a032acae3ddda9$export$d06fae2ee68b101e = new $a7a032acae3ddda9$var$Tree();
|
|
695
746
|
|
|
696
747
|
|
|
748
|
+
/*
|
|
749
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
750
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
751
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
752
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
753
|
+
*
|
|
754
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
755
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
756
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
757
|
+
* governing permissions and limitations under the License.
|
|
758
|
+
*/
|
|
697
759
|
|
|
698
760
|
|
|
699
761
|
|
|
700
762
|
|
|
701
763
|
|
|
702
|
-
|
|
703
|
-
function $581a96d6eb128c1b$export$4e328f61c538687f(props = {
|
|
704
|
-
}) {
|
|
764
|
+
function $581a96d6eb128c1b$export$4e328f61c538687f(props = {}) {
|
|
705
765
|
let { autoFocus: autoFocus = false , isTextInput: isTextInput , within: within } = props;
|
|
706
|
-
let state = $aB6Cp$react.useRef({
|
|
766
|
+
let state = (0, $aB6Cp$react.useRef)({
|
|
707
767
|
isFocused: false,
|
|
708
|
-
isFocusVisible: autoFocus || $aB6Cp$reactariainteractions.isFocusVisible()
|
|
768
|
+
isFocusVisible: autoFocus || (0, $aB6Cp$reactariainteractions.isFocusVisible)()
|
|
709
769
|
});
|
|
710
|
-
let [
|
|
711
|
-
let [isFocusVisibleState, setFocusVisible] = $aB6Cp$react.useState(()=>state.current.isFocused && state.current.isFocusVisible
|
|
712
|
-
);
|
|
713
|
-
let
|
|
714
|
-
, []);
|
|
715
|
-
let onFocusChange = $aB6Cp$react.useCallback((isFocused)=>{
|
|
770
|
+
let [isFocused, setFocused] = (0, $aB6Cp$react.useState)(false);
|
|
771
|
+
let [isFocusVisibleState, setFocusVisible] = (0, $aB6Cp$react.useState)(()=>state.current.isFocused && state.current.isFocusVisible);
|
|
772
|
+
let updateState = (0, $aB6Cp$react.useCallback)(()=>setFocusVisible(state.current.isFocused && state.current.isFocusVisible), []);
|
|
773
|
+
let onFocusChange = (0, $aB6Cp$react.useCallback)((isFocused)=>{
|
|
716
774
|
state.current.isFocused = isFocused;
|
|
717
775
|
setFocused(isFocused);
|
|
718
776
|
updateState();
|
|
719
777
|
}, [
|
|
720
778
|
updateState
|
|
721
779
|
]);
|
|
722
|
-
$aB6Cp$reactariainteractions.useFocusVisibleListener((isFocusVisible)=>{
|
|
780
|
+
(0, $aB6Cp$reactariainteractions.useFocusVisibleListener)((isFocusVisible)=>{
|
|
723
781
|
state.current.isFocusVisible = isFocusVisible;
|
|
724
782
|
updateState();
|
|
725
783
|
}, [], {
|
|
726
784
|
isTextInput: isTextInput
|
|
727
785
|
});
|
|
728
|
-
let { focusProps: focusProps } = $aB6Cp$reactariainteractions.useFocus({
|
|
786
|
+
let { focusProps: focusProps } = (0, $aB6Cp$reactariainteractions.useFocus)({
|
|
729
787
|
isDisabled: within,
|
|
730
788
|
onFocusChange: onFocusChange
|
|
731
789
|
});
|
|
732
|
-
let { focusWithinProps: focusWithinProps } = $aB6Cp$reactariainteractions.useFocusWithin({
|
|
790
|
+
let { focusWithinProps: focusWithinProps } = (0, $aB6Cp$reactariainteractions.useFocusWithin)({
|
|
733
791
|
isDisabled: !within,
|
|
734
792
|
onFocusWithinChange: onFocusChange
|
|
735
793
|
});
|
|
736
794
|
return {
|
|
737
|
-
isFocused:
|
|
795
|
+
isFocused: isFocused,
|
|
738
796
|
isFocusVisible: state.current.isFocused && isFocusVisibleState,
|
|
739
797
|
focusProps: within ? focusWithinProps : focusProps
|
|
740
798
|
};
|
|
@@ -743,27 +801,36 @@ function $581a96d6eb128c1b$export$4e328f61c538687f(props = {
|
|
|
743
801
|
|
|
744
802
|
function $dfd8c70b928eb1b3$export$1a38b4ad7f578e1d(props) {
|
|
745
803
|
let { children: children , focusClass: focusClass , focusRingClass: focusRingClass } = props;
|
|
746
|
-
let { isFocused: isFocused , isFocusVisible: isFocusVisible , focusProps: focusProps } = $581a96d6eb128c1b$export$4e328f61c538687f(props);
|
|
747
|
-
let child = ($parcel$interopDefault($aB6Cp$react)).Children.only(children);
|
|
748
|
-
return
|
|
804
|
+
let { isFocused: isFocused , isFocusVisible: isFocusVisible , focusProps: focusProps } = (0, $581a96d6eb128c1b$export$4e328f61c538687f)(props);
|
|
805
|
+
let child = (0, ($parcel$interopDefault($aB6Cp$react))).Children.only(children);
|
|
806
|
+
return /*#__PURE__*/ (0, ($parcel$interopDefault($aB6Cp$react))).cloneElement(child, (0, $aB6Cp$reactariautils.mergeProps)(child.props, {
|
|
749
807
|
...focusProps,
|
|
750
|
-
className: ($parcel$interopDefault($aB6Cp$clsx))({
|
|
751
|
-
[focusClass ||
|
|
752
|
-
[focusRingClass ||
|
|
808
|
+
className: (0, ($parcel$interopDefault($aB6Cp$clsx)))({
|
|
809
|
+
[focusClass || ""]: isFocused,
|
|
810
|
+
[focusRingClass || ""]: isFocusVisible
|
|
753
811
|
})
|
|
754
|
-
}))
|
|
812
|
+
}));
|
|
755
813
|
}
|
|
756
814
|
|
|
757
815
|
|
|
816
|
+
/*
|
|
817
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
818
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
819
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
820
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
821
|
+
*
|
|
822
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
823
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
824
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
825
|
+
* governing permissions and limitations under the License.
|
|
826
|
+
*/
|
|
758
827
|
|
|
759
828
|
|
|
760
829
|
|
|
761
|
-
|
|
762
|
-
let $fb504d83237fd6ac$var$FocusableContext = /*#__PURE__*/ ($parcel$interopDefault($aB6Cp$react)).createContext(null);
|
|
830
|
+
let $fb504d83237fd6ac$var$FocusableContext = /*#__PURE__*/ (0, ($parcel$interopDefault($aB6Cp$react))).createContext(null);
|
|
763
831
|
function $fb504d83237fd6ac$var$useFocusableContext(ref) {
|
|
764
|
-
let context = $aB6Cp$react.useContext($fb504d83237fd6ac$var$FocusableContext) || {
|
|
765
|
-
|
|
766
|
-
$aB6Cp$reactariautils.useSyncRef(context, ref);
|
|
832
|
+
let context = (0, $aB6Cp$react.useContext)($fb504d83237fd6ac$var$FocusableContext) || {};
|
|
833
|
+
(0, $aB6Cp$reactariautils.useSyncRef)(context, ref);
|
|
767
834
|
// eslint-disable-next-line
|
|
768
835
|
let { ref: _ , ...otherProps } = context;
|
|
769
836
|
return otherProps;
|
|
@@ -776,27 +843,26 @@ function $fb504d83237fd6ac$var$useFocusableContext(ref) {
|
|
|
776
843
|
...otherProps,
|
|
777
844
|
ref: ref
|
|
778
845
|
};
|
|
779
|
-
return
|
|
846
|
+
return /*#__PURE__*/ (0, ($parcel$interopDefault($aB6Cp$react))).createElement($fb504d83237fd6ac$var$FocusableContext.Provider, {
|
|
780
847
|
value: context
|
|
781
|
-
}, children)
|
|
848
|
+
}, children);
|
|
782
849
|
}
|
|
783
|
-
let $fb504d83237fd6ac$export$13f3202a3e5ddd5 = /*#__PURE__*/ ($parcel$interopDefault($aB6Cp$react)).forwardRef($fb504d83237fd6ac$var$FocusableProvider);
|
|
850
|
+
let $fb504d83237fd6ac$export$13f3202a3e5ddd5 = /*#__PURE__*/ (0, ($parcel$interopDefault($aB6Cp$react))).forwardRef($fb504d83237fd6ac$var$FocusableProvider);
|
|
784
851
|
function $fb504d83237fd6ac$export$4c014de7c8940b4c(props, domRef) {
|
|
785
|
-
let { focusProps: focusProps } = $aB6Cp$reactariainteractions.useFocus(props);
|
|
786
|
-
let { keyboardProps: keyboardProps } = $aB6Cp$reactariainteractions.useKeyboard(props);
|
|
787
|
-
let interactions = $aB6Cp$reactariautils.mergeProps(focusProps, keyboardProps);
|
|
852
|
+
let { focusProps: focusProps } = (0, $aB6Cp$reactariainteractions.useFocus)(props);
|
|
853
|
+
let { keyboardProps: keyboardProps } = (0, $aB6Cp$reactariainteractions.useKeyboard)(props);
|
|
854
|
+
let interactions = (0, $aB6Cp$reactariautils.mergeProps)(focusProps, keyboardProps);
|
|
788
855
|
let domProps = $fb504d83237fd6ac$var$useFocusableContext(domRef);
|
|
789
|
-
let interactionProps = props.isDisabled ? {
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
if (autoFocusRef.current && domRef.current) $1c7f9157d722357d$export$80f3e147d781571c(domRef.current);
|
|
856
|
+
let interactionProps = props.isDisabled ? {} : domProps;
|
|
857
|
+
let autoFocusRef = (0, $aB6Cp$react.useRef)(props.autoFocus);
|
|
858
|
+
(0, $aB6Cp$react.useEffect)(()=>{
|
|
859
|
+
if (autoFocusRef.current && domRef.current) (0, $1c7f9157d722357d$export$80f3e147d781571c)(domRef.current);
|
|
794
860
|
autoFocusRef.current = false;
|
|
795
861
|
}, [
|
|
796
862
|
domRef
|
|
797
863
|
]);
|
|
798
864
|
return {
|
|
799
|
-
focusableProps: $aB6Cp$reactariautils.mergeProps({
|
|
865
|
+
focusableProps: (0, $aB6Cp$reactariautils.mergeProps)({
|
|
800
866
|
...interactions,
|
|
801
867
|
tabIndex: props.excludeFromTabOrder && !props.isDisabled ? -1 : undefined
|
|
802
868
|
}, interactionProps)
|