@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 CHANGED
@@ -1,6 +1,7 @@
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");
@@ -24,6 +25,10 @@ $parcel$export(module.exports, "OverlayContainer", () => $0775ea8ea6a0565e$expor
24
25
  $parcel$export(module.exports, "useModal", () => $0775ea8ea6a0565e$export$33ffd74ebf07f060);
25
26
  $parcel$export(module.exports, "DismissButton", () => $f69bb3e6457495cc$export$2317d149ed6f78c4);
26
27
  $parcel$export(module.exports, "ariaHideOutside", () => $08ef1685902b6011$export$1c3ebcada18427bf);
28
+ $parcel$export(module.exports, "usePopover", () => $6c2dfcdee3e15e20$export$542a6fd13ac93354);
29
+ $parcel$export(module.exports, "useModalOverlay", () => $11b7e0b04b421e95$export$dbc0f175b25fb0fb);
30
+ $parcel$export(module.exports, "Overlay", () => $745edbb83ab4296f$export$c6fdb837b070b4ff);
31
+ $parcel$export(module.exports, "useOverlayFocusContain", () => $745edbb83ab4296f$export$14c98a7594375490);
27
32
  const $5935ba4d7da2c103$var$AXIS = {
28
33
  top: 'top',
29
34
  bottom: 'top',
@@ -261,7 +266,7 @@ const $9a8aa1b0b336ea3a$export$f6211563215e3b37 = new WeakMap();
261
266
  function $9a8aa1b0b336ea3a$export$18fc8428861184da(opts) {
262
267
  let { triggerRef: triggerRef , isOpen: isOpen , onClose: onClose } = opts;
263
268
  $6Zb2x$react.useEffect(()=>{
264
- if (!isOpen) return;
269
+ if (!isOpen || onClose === null) return;
265
270
  let onScroll = (e)=>{
266
271
  // Ignore if scrolling an scrollable region outside the trigger's tree.
267
272
  let target = e.target;
@@ -326,11 +331,18 @@ function $cd94b4896dd97759$export$d39e1813b3bdd0e1(props) {
326
331
  crossOffset: crossOffset,
327
332
  maxHeight: maxHeight
328
333
  }));
334
+ // eslint-disable-next-line react-hooks/exhaustive-deps
329
335
  }, deps);
330
336
  // Update position when anything changes
337
+ // eslint-disable-next-line react-hooks/exhaustive-deps
331
338
  $6Zb2x$reactariautils.useLayoutEffect(updatePosition, deps);
332
339
  // Update position on window resize
333
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
+ });
334
346
  // Reposition the overlay and do not close on scroll while the visual viewport is resizing.
335
347
  // This will ensure that overlays adjust their positioning when the iOS virtual keyboard appears.
336
348
  let isResizing = $6Zb2x$react.useRef(false);
@@ -362,7 +374,7 @@ function $cd94b4896dd97759$export$d39e1813b3bdd0e1(props) {
362
374
  $9a8aa1b0b336ea3a$export$18fc8428861184da({
363
375
  triggerRef: targetRef,
364
376
  isOpen: isOpen,
365
- onClose: onClose ? close : undefined
377
+ onClose: onClose && close
366
378
  });
367
379
  return {
368
380
  overlayProps: {
@@ -401,6 +413,7 @@ function $cd94b4896dd97759$var$translateRTL(position, direction) {
401
413
 
402
414
 
403
415
 
416
+
404
417
  const $82711f9cb668ecdb$var$visibleOverlays = [];
405
418
  function $82711f9cb668ecdb$export$ea8f71083e90600f(props, ref) {
406
419
  let { onClose: onClose , shouldCloseOnBlur: shouldCloseOnBlur , isOpen: isOpen , isDismissable: isDismissable = false , isKeyboardDismissDisabled: isKeyboardDismissDisabled = false , shouldCloseOnInteractOutside: shouldCloseOnInteractOutside } = props;
@@ -453,6 +466,10 @@ function $82711f9cb668ecdb$export$ea8f71083e90600f(props, ref) {
453
466
  let { focusWithinProps: focusWithinProps } = $6Zb2x$reactariainteractions.useFocusWithin({
454
467
  isDisabled: !shouldCloseOnBlur,
455
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;
456
473
  if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.relatedTarget)) onClose();
457
474
  }
458
475
  });
@@ -1056,6 +1073,7 @@ function $f69bb3e6457495cc$export$2317d149ed6f78c4(props) {
1056
1073
  */ // Keeps a ref count of all hidden elements. Added to when hiding an element, and
1057
1074
  // subtracted from when showing it again. When it reaches zero, aria-hidden is removed.
1058
1075
  let $08ef1685902b6011$var$refCountMap = new WeakMap();
1076
+ let $08ef1685902b6011$var$observerStack = [];
1059
1077
  function $08ef1685902b6011$export$1c3ebcada18427bf(targets, root = document.body) {
1060
1078
  let visibleNodes = new Set(targets);
1061
1079
  let hiddenNodes = new Set();
@@ -1064,11 +1082,10 @@ function $08ef1685902b6011$export$1c3ebcada18427bf(targets, root = document.body
1064
1082
  // If this node is a live announcer, add it to the set of nodes to keep visible.
1065
1083
  if ((node instanceof HTMLElement || node instanceof SVGElement) && node.dataset.liveAnnouncer === 'true') visibleNodes.add(node);
1066
1084
  // Skip this node and its children if it is one of the target nodes, or a live announcer.
1067
- // Also skip children of already hidden nodes, as aria-hidden is recursive.
1068
- if (visibleNodes.has(node) || hiddenNodes.has(node.parentElement)) return NodeFilter.FILTER_REJECT;
1069
- // VoiceOver on iOS has issues hiding elements with role="row". Hide the cells inside instead.
1070
- // https://bugs.webkit.org/show_bug.cgi?id=222623
1071
- if (node instanceof Element && node.getAttribute('role') === 'row') return NodeFilter.FILTER_SKIP;
1085
+ // Also skip children of already hidden nodes, as aria-hidden is recursive. An exception is
1086
+ // made for elements with role="row" since VoiceOver on iOS has issues hiding elements with role="row".
1087
+ // For that case we want to hide the cells inside as well (https://bugs.webkit.org/show_bug.cgi?id=222623).
1088
+ if (visibleNodes.has(node) || hiddenNodes.has(node.parentElement) && node.parentElement.getAttribute('role') !== 'row') return NodeFilter.FILTER_REJECT;
1072
1089
  // Skip this node but continue to children if one of the targets is inside the node.
1073
1090
  if (targets.some((target)=>node.contains(target)
1074
1091
  )) return NodeFilter.FILTER_SKIP;
@@ -1085,6 +1102,9 @@ function $08ef1685902b6011$export$1c3ebcada18427bf(targets, root = document.body
1085
1102
  hiddenNodes.add(node);
1086
1103
  $08ef1685902b6011$var$refCountMap.set(node, refCount + 1);
1087
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();
1088
1108
  let node1 = walker.nextNode();
1089
1109
  while(node1 != null){
1090
1110
  hide(node1);
@@ -1109,6 +1129,18 @@ function $08ef1685902b6011$export$1c3ebcada18427bf(targets, root = document.body
1109
1129
  childList: true,
1110
1130
  subtree: true
1111
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);
1112
1144
  return ()=>{
1113
1145
  observer.disconnect();
1114
1146
  for (let node of hiddenNodes){
@@ -1118,10 +1150,137 @@ function $08ef1685902b6011$export$1c3ebcada18427bf(targets, root = document.body
1118
1150
  $08ef1685902b6011$var$refCountMap.delete(node);
1119
1151
  } else $08ef1685902b6011$var$refCountMap.set(node, count - 1);
1120
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);
1158
+ };
1159
+ }
1160
+
1161
+
1162
+
1163
+
1164
+
1165
+
1166
+
1167
+
1168
+ function $6c2dfcdee3e15e20$export$542a6fd13ac93354(props, state) {
1169
+ let { triggerRef: triggerRef , popoverRef: popoverRef , isNonModal: isNonModal , isKeyboardDismissDisabled: isKeyboardDismissDisabled , ...otherProps } = props;
1170
+ let { overlayProps: overlayProps , underlayProps: underlayProps } = $82711f9cb668ecdb$export$ea8f71083e90600f({
1171
+ isOpen: state.isOpen,
1172
+ onClose: state.close,
1173
+ shouldCloseOnBlur: true,
1174
+ isDismissable: !isNonModal,
1175
+ isKeyboardDismissDisabled: isKeyboardDismissDisabled
1176
+ }, popoverRef);
1177
+ let { overlayProps: positionProps , arrowProps: arrowProps , placement: placement } = $cd94b4896dd97759$export$d39e1813b3bdd0e1({
1178
+ ...otherProps,
1179
+ targetRef: triggerRef,
1180
+ overlayRef: popoverRef,
1181
+ isOpen: state.isOpen,
1182
+ onClose: null
1183
+ });
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([
1199
+ popoverRef.current
1200
+ ]);
1201
+ }, [
1202
+ isNonModal,
1203
+ state.isOpen,
1204
+ popoverRef
1205
+ ]);
1206
+ return {
1207
+ popoverProps: $6Zb2x$reactariautils.mergeProps(overlayProps, positionProps),
1208
+ arrowProps: arrowProps,
1209
+ underlayProps: underlayProps,
1210
+ placement: placement
1211
+ };
1212
+ }
1213
+
1214
+
1215
+
1216
+
1217
+
1218
+
1219
+
1220
+
1221
+
1222
+
1223
+
1224
+ const $745edbb83ab4296f$export$a2200b96afd16271 = /*#__PURE__*/ ($parcel$interopDefault($6Zb2x$react)).createContext(null);
1225
+ function $745edbb83ab4296f$export$c6fdb837b070b4ff(props) {
1226
+ let isSSR = $6Zb2x$reactariassr.useIsSSR();
1227
+ let { portalContainer: portalContainer = isSSR ? null : document.body } = props;
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
+ ]);
1237
+ if (!portalContainer) return null;
1238
+ let contents = /*#__PURE__*/ ($parcel$interopDefault($6Zb2x$react)).createElement($745edbb83ab4296f$export$a2200b96afd16271.Provider, {
1239
+ value: contextValue
1240
+ }, /*#__PURE__*/ ($parcel$interopDefault($6Zb2x$react)).createElement($6Zb2x$reactariafocus.FocusScope, {
1241
+ restoreFocus: true,
1242
+ contain: contain
1243
+ }, props.children));
1244
+ return(/*#__PURE__*/ ($parcel$interopDefault($6Zb2x$reactdom)).createPortal(contents, portalContainer));
1245
+ }
1246
+ function $745edbb83ab4296f$export$14c98a7594375490() {
1247
+ let ctx = $6Zb2x$react.useContext($745edbb83ab4296f$export$a2200b96afd16271);
1248
+ let setContain = ctx === null || ctx === void 0 ? void 0 : ctx.setContain;
1249
+ $6Zb2x$reactariautils.useLayoutEffect(()=>{
1250
+ setContain === null || setContain === void 0 ? void 0 : setContain(true);
1251
+ }, [
1252
+ setContain
1253
+ ]);
1254
+ }
1255
+
1256
+
1257
+
1258
+ function $11b7e0b04b421e95$export$dbc0f175b25fb0fb(props, state, ref) {
1259
+ let { overlayProps: overlayProps , underlayProps: underlayProps } = $82711f9cb668ecdb$export$ea8f71083e90600f({
1260
+ ...props,
1261
+ isOpen: state.isOpen,
1262
+ onClose: state.close
1263
+ }, ref);
1264
+ $5c2f5cd01815d369$export$ee0f7cc6afcd1c18({
1265
+ isDisabled: !state.isOpen
1266
+ });
1267
+ $745edbb83ab4296f$export$14c98a7594375490();
1268
+ $6Zb2x$react.useEffect(()=>{
1269
+ if (state.isOpen) return $08ef1685902b6011$export$1c3ebcada18427bf([
1270
+ ref.current
1271
+ ]);
1272
+ }, [
1273
+ state.isOpen,
1274
+ ref
1275
+ ]);
1276
+ return {
1277
+ modalProps: $6Zb2x$reactariautils.mergeProps(overlayProps),
1278
+ underlayProps: underlayProps
1121
1279
  };
1122
1280
  }
1123
1281
 
1124
1282
 
1125
1283
 
1126
1284
 
1285
+
1127
1286
  //# sourceMappingURL=main.js.map