@react-aria/overlays 3.11.0 → 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 +75 -15
- package/dist/main.js.map +1 -1
- package/dist/module.js +76 -16
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +14 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/Overlay.tsx +6 -4
- package/src/ariaHideOutside.ts +28 -0
- package/src/useCloseOnScroll.ts +1 -1
- package/src/useOverlay.ts +8 -0
- package/src/useOverlayPosition.ts +10 -2
- package/src/usePopover.ts +47 -14
package/dist/main.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
var $6Zb2x$react = require("react");
|
|
2
2
|
var $6Zb2x$reactariautils = require("@react-aria/utils");
|
|
3
3
|
var $6Zb2x$reactariai18n = require("@react-aria/i18n");
|
|
4
|
+
var $6Zb2x$reactariafocus = require("@react-aria/focus");
|
|
4
5
|
var $6Zb2x$reactariainteractions = require("@react-aria/interactions");
|
|
5
6
|
var $6Zb2x$reactdom = require("react-dom");
|
|
6
7
|
var $6Zb2x$reactariassr = require("@react-aria/ssr");
|
|
7
8
|
var $6Zb2x$reactariavisuallyhidden = require("@react-aria/visually-hidden");
|
|
8
|
-
var $6Zb2x$reactariafocus = require("@react-aria/focus");
|
|
9
9
|
|
|
10
10
|
function $parcel$export(e, n, v, s) {
|
|
11
11
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
@@ -266,7 +266,7 @@ const $9a8aa1b0b336ea3a$export$f6211563215e3b37 = new WeakMap();
|
|
|
266
266
|
function $9a8aa1b0b336ea3a$export$18fc8428861184da(opts) {
|
|
267
267
|
let { triggerRef: triggerRef , isOpen: isOpen , onClose: onClose } = opts;
|
|
268
268
|
$6Zb2x$react.useEffect(()=>{
|
|
269
|
-
if (!isOpen) return;
|
|
269
|
+
if (!isOpen || onClose === null) return;
|
|
270
270
|
let onScroll = (e)=>{
|
|
271
271
|
// Ignore if scrolling an scrollable region outside the trigger's tree.
|
|
272
272
|
let target = e.target;
|
|
@@ -331,11 +331,18 @@ function $cd94b4896dd97759$export$d39e1813b3bdd0e1(props) {
|
|
|
331
331
|
crossOffset: crossOffset,
|
|
332
332
|
maxHeight: maxHeight
|
|
333
333
|
}));
|
|
334
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
334
335
|
}, deps);
|
|
335
336
|
// Update position when anything changes
|
|
337
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
336
338
|
$6Zb2x$reactariautils.useLayoutEffect(updatePosition, deps);
|
|
337
339
|
// Update position on window resize
|
|
338
340
|
$cd94b4896dd97759$var$useResize(updatePosition);
|
|
341
|
+
// Update position when the overlay changes size (might need to flip).
|
|
342
|
+
$6Zb2x$reactariautils.useResizeObserver({
|
|
343
|
+
ref: overlayRef,
|
|
344
|
+
onResize: updatePosition
|
|
345
|
+
});
|
|
339
346
|
// Reposition the overlay and do not close on scroll while the visual viewport is resizing.
|
|
340
347
|
// This will ensure that overlays adjust their positioning when the iOS virtual keyboard appears.
|
|
341
348
|
let isResizing = $6Zb2x$react.useRef(false);
|
|
@@ -367,7 +374,7 @@ function $cd94b4896dd97759$export$d39e1813b3bdd0e1(props) {
|
|
|
367
374
|
$9a8aa1b0b336ea3a$export$18fc8428861184da({
|
|
368
375
|
triggerRef: targetRef,
|
|
369
376
|
isOpen: isOpen,
|
|
370
|
-
onClose: onClose
|
|
377
|
+
onClose: onClose && close
|
|
371
378
|
});
|
|
372
379
|
return {
|
|
373
380
|
overlayProps: {
|
|
@@ -406,6 +413,7 @@ function $cd94b4896dd97759$var$translateRTL(position, direction) {
|
|
|
406
413
|
|
|
407
414
|
|
|
408
415
|
|
|
416
|
+
|
|
409
417
|
const $82711f9cb668ecdb$var$visibleOverlays = [];
|
|
410
418
|
function $82711f9cb668ecdb$export$ea8f71083e90600f(props, ref) {
|
|
411
419
|
let { onClose: onClose , shouldCloseOnBlur: shouldCloseOnBlur , isOpen: isOpen , isDismissable: isDismissable = false , isKeyboardDismissDisabled: isKeyboardDismissDisabled = false , shouldCloseOnInteractOutside: shouldCloseOnInteractOutside } = props;
|
|
@@ -458,6 +466,10 @@ function $82711f9cb668ecdb$export$ea8f71083e90600f(props, ref) {
|
|
|
458
466
|
let { focusWithinProps: focusWithinProps } = $6Zb2x$reactariainteractions.useFocusWithin({
|
|
459
467
|
isDisabled: !shouldCloseOnBlur,
|
|
460
468
|
onBlurWithin: (e)=>{
|
|
469
|
+
// If focus is moving into a child focus scope (e.g. menu inside a dialog),
|
|
470
|
+
// do not close the outer overlay. At this point, the active scope should
|
|
471
|
+
// still be the outer overlay, since blur events run before focus.
|
|
472
|
+
if (e.relatedTarget && $6Zb2x$reactariafocus.isElementInChildOfActiveScope(e.relatedTarget)) return;
|
|
461
473
|
if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.relatedTarget)) onClose();
|
|
462
474
|
}
|
|
463
475
|
});
|
|
@@ -1061,6 +1073,7 @@ function $f69bb3e6457495cc$export$2317d149ed6f78c4(props) {
|
|
|
1061
1073
|
*/ // Keeps a ref count of all hidden elements. Added to when hiding an element, and
|
|
1062
1074
|
// subtracted from when showing it again. When it reaches zero, aria-hidden is removed.
|
|
1063
1075
|
let $08ef1685902b6011$var$refCountMap = new WeakMap();
|
|
1076
|
+
let $08ef1685902b6011$var$observerStack = [];
|
|
1064
1077
|
function $08ef1685902b6011$export$1c3ebcada18427bf(targets, root = document.body) {
|
|
1065
1078
|
let visibleNodes = new Set(targets);
|
|
1066
1079
|
let hiddenNodes = new Set();
|
|
@@ -1089,6 +1102,9 @@ function $08ef1685902b6011$export$1c3ebcada18427bf(targets, root = document.body
|
|
|
1089
1102
|
hiddenNodes.add(node);
|
|
1090
1103
|
$08ef1685902b6011$var$refCountMap.set(node, refCount + 1);
|
|
1091
1104
|
};
|
|
1105
|
+
// If there is already a MutationObserver listening from a previous call,
|
|
1106
|
+
// disconnect it so the new on takes over.
|
|
1107
|
+
if ($08ef1685902b6011$var$observerStack.length) $08ef1685902b6011$var$observerStack[$08ef1685902b6011$var$observerStack.length - 1].disconnect();
|
|
1092
1108
|
let node1 = walker.nextNode();
|
|
1093
1109
|
while(node1 != null){
|
|
1094
1110
|
hide(node1);
|
|
@@ -1113,6 +1129,18 @@ function $08ef1685902b6011$export$1c3ebcada18427bf(targets, root = document.body
|
|
|
1113
1129
|
childList: true,
|
|
1114
1130
|
subtree: true
|
|
1115
1131
|
});
|
|
1132
|
+
let observerWrapper = {
|
|
1133
|
+
observe () {
|
|
1134
|
+
observer.observe(root, {
|
|
1135
|
+
childList: true,
|
|
1136
|
+
subtree: true
|
|
1137
|
+
});
|
|
1138
|
+
},
|
|
1139
|
+
disconnect () {
|
|
1140
|
+
observer.disconnect();
|
|
1141
|
+
}
|
|
1142
|
+
};
|
|
1143
|
+
$08ef1685902b6011$var$observerStack.push(observerWrapper);
|
|
1116
1144
|
return ()=>{
|
|
1117
1145
|
observer.disconnect();
|
|
1118
1146
|
for (let node of hiddenNodes){
|
|
@@ -1122,6 +1150,11 @@ function $08ef1685902b6011$export$1c3ebcada18427bf(targets, root = document.body
|
|
|
1122
1150
|
$08ef1685902b6011$var$refCountMap.delete(node);
|
|
1123
1151
|
} else $08ef1685902b6011$var$refCountMap.set(node, count - 1);
|
|
1124
1152
|
}
|
|
1153
|
+
// Remove this observer from the stack, and start the previous one.
|
|
1154
|
+
if (observerWrapper === $08ef1685902b6011$var$observerStack[$08ef1685902b6011$var$observerStack.length - 1]) {
|
|
1155
|
+
$08ef1685902b6011$var$observerStack.pop();
|
|
1156
|
+
if ($08ef1685902b6011$var$observerStack.length) $08ef1685902b6011$var$observerStack[$08ef1685902b6011$var$observerStack.length - 1].observe();
|
|
1157
|
+
} else $08ef1685902b6011$var$observerStack.splice($08ef1685902b6011$var$observerStack.indexOf(observerWrapper), 1);
|
|
1125
1158
|
};
|
|
1126
1159
|
}
|
|
1127
1160
|
|
|
@@ -1131,22 +1164,38 @@ function $08ef1685902b6011$export$1c3ebcada18427bf(targets, root = document.body
|
|
|
1131
1164
|
|
|
1132
1165
|
|
|
1133
1166
|
|
|
1167
|
+
|
|
1134
1168
|
function $6c2dfcdee3e15e20$export$542a6fd13ac93354(props, state) {
|
|
1135
|
-
let { triggerRef: triggerRef , popoverRef: popoverRef , isNonModal: isNonModal , ...otherProps } = props;
|
|
1136
|
-
let { overlayProps: overlayProps } = $82711f9cb668ecdb$export$ea8f71083e90600f({
|
|
1169
|
+
let { triggerRef: triggerRef , popoverRef: popoverRef , isNonModal: isNonModal , isKeyboardDismissDisabled: isKeyboardDismissDisabled , ...otherProps } = props;
|
|
1170
|
+
let { overlayProps: overlayProps , underlayProps: underlayProps } = $82711f9cb668ecdb$export$ea8f71083e90600f({
|
|
1137
1171
|
isOpen: state.isOpen,
|
|
1138
1172
|
onClose: state.close,
|
|
1139
1173
|
shouldCloseOnBlur: true,
|
|
1140
|
-
isDismissable:
|
|
1174
|
+
isDismissable: !isNonModal,
|
|
1175
|
+
isKeyboardDismissDisabled: isKeyboardDismissDisabled
|
|
1141
1176
|
}, popoverRef);
|
|
1142
|
-
let { overlayProps: positionProps , arrowProps: arrowProps } = $cd94b4896dd97759$export$d39e1813b3bdd0e1({
|
|
1177
|
+
let { overlayProps: positionProps , arrowProps: arrowProps , placement: placement } = $cd94b4896dd97759$export$d39e1813b3bdd0e1({
|
|
1143
1178
|
...otherProps,
|
|
1144
1179
|
targetRef: triggerRef,
|
|
1145
1180
|
overlayRef: popoverRef,
|
|
1146
|
-
isOpen: state.isOpen
|
|
1181
|
+
isOpen: state.isOpen,
|
|
1182
|
+
onClose: null
|
|
1147
1183
|
});
|
|
1148
|
-
|
|
1149
|
-
|
|
1184
|
+
// Delay preventing scroll until popover is positioned to avoid extra scroll padding.
|
|
1185
|
+
// This requires a layout effect so that positioning has been committed to the DOM
|
|
1186
|
+
// by the time usePreventScroll measures the element.
|
|
1187
|
+
let [isPositioned, setPositioned] = $6Zb2x$react.useState(false);
|
|
1188
|
+
$6Zb2x$reactariautils.useLayoutEffect(()=>{
|
|
1189
|
+
if (!isNonModal && placement) setPositioned(true);
|
|
1190
|
+
}, [
|
|
1191
|
+
isNonModal,
|
|
1192
|
+
placement
|
|
1193
|
+
]);
|
|
1194
|
+
$5c2f5cd01815d369$export$ee0f7cc6afcd1c18({
|
|
1195
|
+
isDisabled: isNonModal || !isPositioned
|
|
1196
|
+
});
|
|
1197
|
+
$6Zb2x$reactariautils.useLayoutEffect(()=>{
|
|
1198
|
+
if (state.isOpen && !isNonModal && popoverRef.current) return $08ef1685902b6011$export$1c3ebcada18427bf([
|
|
1150
1199
|
popoverRef.current
|
|
1151
1200
|
]);
|
|
1152
1201
|
}, [
|
|
@@ -1156,7 +1205,9 @@ function $6c2dfcdee3e15e20$export$542a6fd13ac93354(props, state) {
|
|
|
1156
1205
|
]);
|
|
1157
1206
|
return {
|
|
1158
1207
|
popoverProps: $6Zb2x$reactariautils.mergeProps(overlayProps, positionProps),
|
|
1159
|
-
arrowProps: arrowProps
|
|
1208
|
+
arrowProps: arrowProps,
|
|
1209
|
+
underlayProps: underlayProps,
|
|
1210
|
+
placement: placement
|
|
1160
1211
|
};
|
|
1161
1212
|
}
|
|
1162
1213
|
|
|
@@ -1170,14 +1221,22 @@ function $6c2dfcdee3e15e20$export$542a6fd13ac93354(props, state) {
|
|
|
1170
1221
|
|
|
1171
1222
|
|
|
1172
1223
|
|
|
1173
|
-
const $745edbb83ab4296f$
|
|
1224
|
+
const $745edbb83ab4296f$export$a2200b96afd16271 = /*#__PURE__*/ ($parcel$interopDefault($6Zb2x$react)).createContext(null);
|
|
1174
1225
|
function $745edbb83ab4296f$export$c6fdb837b070b4ff(props) {
|
|
1175
1226
|
let isSSR = $6Zb2x$reactariassr.useIsSSR();
|
|
1176
1227
|
let { portalContainer: portalContainer = isSSR ? null : document.body } = props;
|
|
1177
1228
|
let [contain, setContain] = $6Zb2x$react.useState(false);
|
|
1229
|
+
let contextValue = $6Zb2x$react.useMemo(()=>({
|
|
1230
|
+
contain: contain,
|
|
1231
|
+
setContain: setContain
|
|
1232
|
+
})
|
|
1233
|
+
, [
|
|
1234
|
+
contain,
|
|
1235
|
+
setContain
|
|
1236
|
+
]);
|
|
1178
1237
|
if (!portalContainer) return null;
|
|
1179
|
-
let contents = /*#__PURE__*/ ($parcel$interopDefault($6Zb2x$react)).createElement($745edbb83ab4296f$
|
|
1180
|
-
value:
|
|
1238
|
+
let contents = /*#__PURE__*/ ($parcel$interopDefault($6Zb2x$react)).createElement($745edbb83ab4296f$export$a2200b96afd16271.Provider, {
|
|
1239
|
+
value: contextValue
|
|
1181
1240
|
}, /*#__PURE__*/ ($parcel$interopDefault($6Zb2x$react)).createElement($6Zb2x$reactariafocus.FocusScope, {
|
|
1182
1241
|
restoreFocus: true,
|
|
1183
1242
|
contain: contain
|
|
@@ -1185,7 +1244,8 @@ function $745edbb83ab4296f$export$c6fdb837b070b4ff(props) {
|
|
|
1185
1244
|
return(/*#__PURE__*/ ($parcel$interopDefault($6Zb2x$reactdom)).createPortal(contents, portalContainer));
|
|
1186
1245
|
}
|
|
1187
1246
|
function $745edbb83ab4296f$export$14c98a7594375490() {
|
|
1188
|
-
let
|
|
1247
|
+
let ctx = $6Zb2x$react.useContext($745edbb83ab4296f$export$a2200b96afd16271);
|
|
1248
|
+
let setContain = ctx === null || ctx === void 0 ? void 0 : ctx.setContain;
|
|
1189
1249
|
$6Zb2x$reactariautils.useLayoutEffect(()=>{
|
|
1190
1250
|
setContain === null || setContain === void 0 ? void 0 : setContain(true);
|
|
1191
1251
|
}, [
|