@react-aria/overlays 3.10.1 → 3.12.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/main.js +166 -7
- package/dist/main.js.map +1 -1
- package/dist/module.js +164 -9
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +82 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +12 -11
- package/src/Overlay.tsx +63 -0
- package/src/ariaHideOutside.ts +32 -8
- package/src/index.ts +6 -0
- package/src/useCloseOnScroll.ts +1 -1
- package/src/useModalOverlay.ts +69 -0
- package/src/useOverlay.ts +8 -0
- package/src/useOverlayPosition.ts +10 -2
- package/src/usePopover.ts +121 -0
package/dist/module.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import $k7QOs$react, {useState as $k7QOs$useState, useCallback as $k7QOs$useCallback, useRef as $k7QOs$useRef, useEffect as $k7QOs$useEffect, useContext as $k7QOs$useContext, useMemo as $k7QOs$useMemo} from "react";
|
|
2
|
-
import {useLayoutEffect as $k7QOs$useLayoutEffect, useId as $k7QOs$useId, isIOS as $k7QOs$isIOS, chain as $k7QOs$chain, getScrollParent as $k7QOs$getScrollParent, useLabels as $k7QOs$useLabels} from "@react-aria/utils";
|
|
2
|
+
import {useLayoutEffect as $k7QOs$useLayoutEffect, useResizeObserver as $k7QOs$useResizeObserver, useId as $k7QOs$useId, isIOS as $k7QOs$isIOS, chain as $k7QOs$chain, getScrollParent as $k7QOs$getScrollParent, useLabels as $k7QOs$useLabels, mergeProps as $k7QOs$mergeProps} from "@react-aria/utils";
|
|
3
3
|
import {useLocale as $k7QOs$useLocale, useLocalizedStringFormatter as $k7QOs$useLocalizedStringFormatter} from "@react-aria/i18n";
|
|
4
|
+
import {isElementInChildOfActiveScope as $k7QOs$isElementInChildOfActiveScope, FocusScope as $k7QOs$FocusScope} from "@react-aria/focus";
|
|
4
5
|
import {useInteractOutside as $k7QOs$useInteractOutside, useFocusWithin as $k7QOs$useFocusWithin} from "@react-aria/interactions";
|
|
5
6
|
import $k7QOs$reactdom from "react-dom";
|
|
6
7
|
import {useIsSSR as $k7QOs$useIsSSR} from "@react-aria/ssr";
|
|
@@ -246,7 +247,7 @@ const $dd149f63282afbbf$export$f6211563215e3b37 = new WeakMap();
|
|
|
246
247
|
function $dd149f63282afbbf$export$18fc8428861184da(opts) {
|
|
247
248
|
let { triggerRef: triggerRef , isOpen: isOpen , onClose: onClose } = opts;
|
|
248
249
|
$k7QOs$useEffect(()=>{
|
|
249
|
-
if (!isOpen) return;
|
|
250
|
+
if (!isOpen || onClose === null) return;
|
|
250
251
|
let onScroll = (e)=>{
|
|
251
252
|
// Ignore if scrolling an scrollable region outside the trigger's tree.
|
|
252
253
|
let target = e.target;
|
|
@@ -311,11 +312,18 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
311
312
|
crossOffset: crossOffset,
|
|
312
313
|
maxHeight: maxHeight
|
|
313
314
|
}));
|
|
315
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
314
316
|
}, deps);
|
|
315
317
|
// Update position when anything changes
|
|
318
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
316
319
|
$k7QOs$useLayoutEffect(updatePosition, deps);
|
|
317
320
|
// Update position on window resize
|
|
318
321
|
$2a41e45df1593e64$var$useResize(updatePosition);
|
|
322
|
+
// Update position when the overlay changes size (might need to flip).
|
|
323
|
+
$k7QOs$useResizeObserver({
|
|
324
|
+
ref: overlayRef,
|
|
325
|
+
onResize: updatePosition
|
|
326
|
+
});
|
|
319
327
|
// Reposition the overlay and do not close on scroll while the visual viewport is resizing.
|
|
320
328
|
// This will ensure that overlays adjust their positioning when the iOS virtual keyboard appears.
|
|
321
329
|
let isResizing = $k7QOs$useRef(false);
|
|
@@ -347,7 +355,7 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
347
355
|
$dd149f63282afbbf$export$18fc8428861184da({
|
|
348
356
|
triggerRef: targetRef,
|
|
349
357
|
isOpen: isOpen,
|
|
350
|
-
onClose: onClose
|
|
358
|
+
onClose: onClose && close
|
|
351
359
|
});
|
|
352
360
|
return {
|
|
353
361
|
overlayProps: {
|
|
@@ -386,6 +394,7 @@ function $2a41e45df1593e64$var$translateRTL(position, direction) {
|
|
|
386
394
|
|
|
387
395
|
|
|
388
396
|
|
|
397
|
+
|
|
389
398
|
const $a11501f3d1d39e6c$var$visibleOverlays = [];
|
|
390
399
|
function $a11501f3d1d39e6c$export$ea8f71083e90600f(props, ref) {
|
|
391
400
|
let { onClose: onClose , shouldCloseOnBlur: shouldCloseOnBlur , isOpen: isOpen , isDismissable: isDismissable = false , isKeyboardDismissDisabled: isKeyboardDismissDisabled = false , shouldCloseOnInteractOutside: shouldCloseOnInteractOutside } = props;
|
|
@@ -438,6 +447,10 @@ function $a11501f3d1d39e6c$export$ea8f71083e90600f(props, ref) {
|
|
|
438
447
|
let { focusWithinProps: focusWithinProps } = $k7QOs$useFocusWithin({
|
|
439
448
|
isDisabled: !shouldCloseOnBlur,
|
|
440
449
|
onBlurWithin: (e)=>{
|
|
450
|
+
// If focus is moving into a child focus scope (e.g. menu inside a dialog),
|
|
451
|
+
// do not close the outer overlay. At this point, the active scope should
|
|
452
|
+
// still be the outer overlay, since blur events run before focus.
|
|
453
|
+
if (e.relatedTarget && $k7QOs$isElementInChildOfActiveScope(e.relatedTarget)) return;
|
|
441
454
|
if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.relatedTarget)) onClose();
|
|
442
455
|
}
|
|
443
456
|
});
|
|
@@ -1041,6 +1054,7 @@ function $86ea4cb521eb2e37$export$2317d149ed6f78c4(props) {
|
|
|
1041
1054
|
*/ // Keeps a ref count of all hidden elements. Added to when hiding an element, and
|
|
1042
1055
|
// subtracted from when showing it again. When it reaches zero, aria-hidden is removed.
|
|
1043
1056
|
let $5e3802645cc19319$var$refCountMap = new WeakMap();
|
|
1057
|
+
let $5e3802645cc19319$var$observerStack = [];
|
|
1044
1058
|
function $5e3802645cc19319$export$1c3ebcada18427bf(targets, root = document.body) {
|
|
1045
1059
|
let visibleNodes = new Set(targets);
|
|
1046
1060
|
let hiddenNodes = new Set();
|
|
@@ -1049,11 +1063,10 @@ function $5e3802645cc19319$export$1c3ebcada18427bf(targets, root = document.body
|
|
|
1049
1063
|
// If this node is a live announcer, add it to the set of nodes to keep visible.
|
|
1050
1064
|
if ((node instanceof HTMLElement || node instanceof SVGElement) && node.dataset.liveAnnouncer === 'true') visibleNodes.add(node);
|
|
1051
1065
|
// Skip this node and its children if it is one of the target nodes, or a live announcer.
|
|
1052
|
-
// Also skip children of already hidden nodes, as aria-hidden is recursive.
|
|
1053
|
-
|
|
1054
|
-
//
|
|
1055
|
-
|
|
1056
|
-
if (node instanceof Element && node.getAttribute('role') === 'row') return NodeFilter.FILTER_SKIP;
|
|
1066
|
+
// Also skip children of already hidden nodes, as aria-hidden is recursive. An exception is
|
|
1067
|
+
// made for elements with role="row" since VoiceOver on iOS has issues hiding elements with role="row".
|
|
1068
|
+
// For that case we want to hide the cells inside as well (https://bugs.webkit.org/show_bug.cgi?id=222623).
|
|
1069
|
+
if (visibleNodes.has(node) || hiddenNodes.has(node.parentElement) && node.parentElement.getAttribute('role') !== 'row') return NodeFilter.FILTER_REJECT;
|
|
1057
1070
|
// Skip this node but continue to children if one of the targets is inside the node.
|
|
1058
1071
|
if (targets.some((target)=>node.contains(target)
|
|
1059
1072
|
)) return NodeFilter.FILTER_SKIP;
|
|
@@ -1070,6 +1083,9 @@ function $5e3802645cc19319$export$1c3ebcada18427bf(targets, root = document.body
|
|
|
1070
1083
|
hiddenNodes.add(node);
|
|
1071
1084
|
$5e3802645cc19319$var$refCountMap.set(node, refCount + 1);
|
|
1072
1085
|
};
|
|
1086
|
+
// If there is already a MutationObserver listening from a previous call,
|
|
1087
|
+
// disconnect it so the new on takes over.
|
|
1088
|
+
if ($5e3802645cc19319$var$observerStack.length) $5e3802645cc19319$var$observerStack[$5e3802645cc19319$var$observerStack.length - 1].disconnect();
|
|
1073
1089
|
let node1 = walker.nextNode();
|
|
1074
1090
|
while(node1 != null){
|
|
1075
1091
|
hide(node1);
|
|
@@ -1094,6 +1110,18 @@ function $5e3802645cc19319$export$1c3ebcada18427bf(targets, root = document.body
|
|
|
1094
1110
|
childList: true,
|
|
1095
1111
|
subtree: true
|
|
1096
1112
|
});
|
|
1113
|
+
let observerWrapper = {
|
|
1114
|
+
observe () {
|
|
1115
|
+
observer.observe(root, {
|
|
1116
|
+
childList: true,
|
|
1117
|
+
subtree: true
|
|
1118
|
+
});
|
|
1119
|
+
},
|
|
1120
|
+
disconnect () {
|
|
1121
|
+
observer.disconnect();
|
|
1122
|
+
}
|
|
1123
|
+
};
|
|
1124
|
+
$5e3802645cc19319$var$observerStack.push(observerWrapper);
|
|
1097
1125
|
return ()=>{
|
|
1098
1126
|
observer.disconnect();
|
|
1099
1127
|
for (let node of hiddenNodes){
|
|
@@ -1103,11 +1131,138 @@ function $5e3802645cc19319$export$1c3ebcada18427bf(targets, root = document.body
|
|
|
1103
1131
|
$5e3802645cc19319$var$refCountMap.delete(node);
|
|
1104
1132
|
} else $5e3802645cc19319$var$refCountMap.set(node, count - 1);
|
|
1105
1133
|
}
|
|
1134
|
+
// Remove this observer from the stack, and start the previous one.
|
|
1135
|
+
if (observerWrapper === $5e3802645cc19319$var$observerStack[$5e3802645cc19319$var$observerStack.length - 1]) {
|
|
1136
|
+
$5e3802645cc19319$var$observerStack.pop();
|
|
1137
|
+
if ($5e3802645cc19319$var$observerStack.length) $5e3802645cc19319$var$observerStack[$5e3802645cc19319$var$observerStack.length - 1].observe();
|
|
1138
|
+
} else $5e3802645cc19319$var$observerStack.splice($5e3802645cc19319$var$observerStack.indexOf(observerWrapper), 1);
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
|
|
1143
|
+
|
|
1144
|
+
|
|
1145
|
+
|
|
1146
|
+
|
|
1147
|
+
|
|
1148
|
+
|
|
1149
|
+
function $f2f8a6077418541e$export$542a6fd13ac93354(props, state) {
|
|
1150
|
+
let { triggerRef: triggerRef , popoverRef: popoverRef , isNonModal: isNonModal , isKeyboardDismissDisabled: isKeyboardDismissDisabled , ...otherProps } = props;
|
|
1151
|
+
let { overlayProps: overlayProps , underlayProps: underlayProps } = $a11501f3d1d39e6c$export$ea8f71083e90600f({
|
|
1152
|
+
isOpen: state.isOpen,
|
|
1153
|
+
onClose: state.close,
|
|
1154
|
+
shouldCloseOnBlur: true,
|
|
1155
|
+
isDismissable: !isNonModal,
|
|
1156
|
+
isKeyboardDismissDisabled: isKeyboardDismissDisabled
|
|
1157
|
+
}, popoverRef);
|
|
1158
|
+
let { overlayProps: positionProps , arrowProps: arrowProps , placement: placement } = $2a41e45df1593e64$export$d39e1813b3bdd0e1({
|
|
1159
|
+
...otherProps,
|
|
1160
|
+
targetRef: triggerRef,
|
|
1161
|
+
overlayRef: popoverRef,
|
|
1162
|
+
isOpen: state.isOpen,
|
|
1163
|
+
onClose: null
|
|
1164
|
+
});
|
|
1165
|
+
// Delay preventing scroll until popover is positioned to avoid extra scroll padding.
|
|
1166
|
+
// This requires a layout effect so that positioning has been committed to the DOM
|
|
1167
|
+
// by the time usePreventScroll measures the element.
|
|
1168
|
+
let [isPositioned, setPositioned] = $k7QOs$useState(false);
|
|
1169
|
+
$k7QOs$useLayoutEffect(()=>{
|
|
1170
|
+
if (!isNonModal && placement) setPositioned(true);
|
|
1171
|
+
}, [
|
|
1172
|
+
isNonModal,
|
|
1173
|
+
placement
|
|
1174
|
+
]);
|
|
1175
|
+
$49c51c25361d4cd2$export$ee0f7cc6afcd1c18({
|
|
1176
|
+
isDisabled: isNonModal || !isPositioned
|
|
1177
|
+
});
|
|
1178
|
+
$k7QOs$useLayoutEffect(()=>{
|
|
1179
|
+
if (state.isOpen && !isNonModal && popoverRef.current) return $5e3802645cc19319$export$1c3ebcada18427bf([
|
|
1180
|
+
popoverRef.current
|
|
1181
|
+
]);
|
|
1182
|
+
}, [
|
|
1183
|
+
isNonModal,
|
|
1184
|
+
state.isOpen,
|
|
1185
|
+
popoverRef
|
|
1186
|
+
]);
|
|
1187
|
+
return {
|
|
1188
|
+
popoverProps: $k7QOs$mergeProps(overlayProps, positionProps),
|
|
1189
|
+
arrowProps: arrowProps,
|
|
1190
|
+
underlayProps: underlayProps,
|
|
1191
|
+
placement: placement
|
|
1192
|
+
};
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
|
|
1196
|
+
|
|
1197
|
+
|
|
1198
|
+
|
|
1199
|
+
|
|
1200
|
+
|
|
1201
|
+
|
|
1202
|
+
|
|
1203
|
+
|
|
1204
|
+
|
|
1205
|
+
const $337b884510726a0d$export$a2200b96afd16271 = /*#__PURE__*/ $k7QOs$react.createContext(null);
|
|
1206
|
+
function $337b884510726a0d$export$c6fdb837b070b4ff(props) {
|
|
1207
|
+
let isSSR = $k7QOs$useIsSSR();
|
|
1208
|
+
let { portalContainer: portalContainer = isSSR ? null : document.body } = props;
|
|
1209
|
+
let [contain, setContain] = $k7QOs$useState(false);
|
|
1210
|
+
let contextValue = $k7QOs$useMemo(()=>({
|
|
1211
|
+
contain: contain,
|
|
1212
|
+
setContain: setContain
|
|
1213
|
+
})
|
|
1214
|
+
, [
|
|
1215
|
+
contain,
|
|
1216
|
+
setContain
|
|
1217
|
+
]);
|
|
1218
|
+
if (!portalContainer) return null;
|
|
1219
|
+
let contents = /*#__PURE__*/ $k7QOs$react.createElement($337b884510726a0d$export$a2200b96afd16271.Provider, {
|
|
1220
|
+
value: contextValue
|
|
1221
|
+
}, /*#__PURE__*/ $k7QOs$react.createElement($k7QOs$FocusScope, {
|
|
1222
|
+
restoreFocus: true,
|
|
1223
|
+
contain: contain
|
|
1224
|
+
}, props.children));
|
|
1225
|
+
return(/*#__PURE__*/ $k7QOs$reactdom.createPortal(contents, portalContainer));
|
|
1226
|
+
}
|
|
1227
|
+
function $337b884510726a0d$export$14c98a7594375490() {
|
|
1228
|
+
let ctx = $k7QOs$useContext($337b884510726a0d$export$a2200b96afd16271);
|
|
1229
|
+
let setContain = ctx === null || ctx === void 0 ? void 0 : ctx.setContain;
|
|
1230
|
+
$k7QOs$useLayoutEffect(()=>{
|
|
1231
|
+
setContain === null || setContain === void 0 ? void 0 : setContain(true);
|
|
1232
|
+
}, [
|
|
1233
|
+
setContain
|
|
1234
|
+
]);
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
|
|
1238
|
+
|
|
1239
|
+
function $8ac8429251c45e4b$export$dbc0f175b25fb0fb(props, state, ref) {
|
|
1240
|
+
let { overlayProps: overlayProps , underlayProps: underlayProps } = $a11501f3d1d39e6c$export$ea8f71083e90600f({
|
|
1241
|
+
...props,
|
|
1242
|
+
isOpen: state.isOpen,
|
|
1243
|
+
onClose: state.close
|
|
1244
|
+
}, ref);
|
|
1245
|
+
$49c51c25361d4cd2$export$ee0f7cc6afcd1c18({
|
|
1246
|
+
isDisabled: !state.isOpen
|
|
1247
|
+
});
|
|
1248
|
+
$337b884510726a0d$export$14c98a7594375490();
|
|
1249
|
+
$k7QOs$useEffect(()=>{
|
|
1250
|
+
if (state.isOpen) return $5e3802645cc19319$export$1c3ebcada18427bf([
|
|
1251
|
+
ref.current
|
|
1252
|
+
]);
|
|
1253
|
+
}, [
|
|
1254
|
+
state.isOpen,
|
|
1255
|
+
ref
|
|
1256
|
+
]);
|
|
1257
|
+
return {
|
|
1258
|
+
modalProps: $k7QOs$mergeProps(overlayProps),
|
|
1259
|
+
underlayProps: underlayProps
|
|
1106
1260
|
};
|
|
1107
1261
|
}
|
|
1108
1262
|
|
|
1109
1263
|
|
|
1110
1264
|
|
|
1111
1265
|
|
|
1112
|
-
|
|
1266
|
+
|
|
1267
|
+
export {$2a41e45df1593e64$export$d39e1813b3bdd0e1 as useOverlayPosition, $a11501f3d1d39e6c$export$ea8f71083e90600f as useOverlay, $628037886ba31236$export$f9d5c8beee7d008d as useOverlayTrigger, $49c51c25361d4cd2$export$ee0f7cc6afcd1c18 as usePreventScroll, $f57aed4a881a3485$export$178405afcd8c5eb as ModalProvider, $f57aed4a881a3485$export$d9aaed4c3ece1bc0 as useModalProvider, $f57aed4a881a3485$export$bf688221f59024e5 as OverlayProvider, $f57aed4a881a3485$export$b47c3594eab58386 as OverlayContainer, $f57aed4a881a3485$export$33ffd74ebf07f060 as useModal, $86ea4cb521eb2e37$export$2317d149ed6f78c4 as DismissButton, $5e3802645cc19319$export$1c3ebcada18427bf as ariaHideOutside, $f2f8a6077418541e$export$542a6fd13ac93354 as usePopover, $8ac8429251c45e4b$export$dbc0f175b25fb0fb as useModalOverlay, $337b884510726a0d$export$c6fdb837b070b4ff as Overlay, $337b884510726a0d$export$14c98a7594375490 as useOverlayFocusContain};
|
|
1113
1268
|
//# sourceMappingURL=module.js.map
|