@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/module.js CHANGED
@@ -1,11 +1,11 @@
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, mergeProps as $k7QOs$mergeProps} 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";
7
8
  import {VisuallyHidden as $k7QOs$VisuallyHidden} from "@react-aria/visually-hidden";
8
- import {FocusScope as $k7QOs$FocusScope} from "@react-aria/focus";
9
9
 
10
10
  function $parcel$interopDefault(a) {
11
11
  return a && a.__esModule ? a.default : a;
@@ -247,7 +247,7 @@ const $dd149f63282afbbf$export$f6211563215e3b37 = new WeakMap();
247
247
  function $dd149f63282afbbf$export$18fc8428861184da(opts) {
248
248
  let { triggerRef: triggerRef , isOpen: isOpen , onClose: onClose } = opts;
249
249
  $k7QOs$useEffect(()=>{
250
- if (!isOpen) return;
250
+ if (!isOpen || onClose === null) return;
251
251
  let onScroll = (e)=>{
252
252
  // Ignore if scrolling an scrollable region outside the trigger's tree.
253
253
  let target = e.target;
@@ -312,11 +312,18 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
312
312
  crossOffset: crossOffset,
313
313
  maxHeight: maxHeight
314
314
  }));
315
+ // eslint-disable-next-line react-hooks/exhaustive-deps
315
316
  }, deps);
316
317
  // Update position when anything changes
318
+ // eslint-disable-next-line react-hooks/exhaustive-deps
317
319
  $k7QOs$useLayoutEffect(updatePosition, deps);
318
320
  // Update position on window resize
319
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
+ });
320
327
  // Reposition the overlay and do not close on scroll while the visual viewport is resizing.
321
328
  // This will ensure that overlays adjust their positioning when the iOS virtual keyboard appears.
322
329
  let isResizing = $k7QOs$useRef(false);
@@ -348,7 +355,7 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
348
355
  $dd149f63282afbbf$export$18fc8428861184da({
349
356
  triggerRef: targetRef,
350
357
  isOpen: isOpen,
351
- onClose: onClose ? close : undefined
358
+ onClose: onClose && close
352
359
  });
353
360
  return {
354
361
  overlayProps: {
@@ -387,6 +394,7 @@ function $2a41e45df1593e64$var$translateRTL(position, direction) {
387
394
 
388
395
 
389
396
 
397
+
390
398
  const $a11501f3d1d39e6c$var$visibleOverlays = [];
391
399
  function $a11501f3d1d39e6c$export$ea8f71083e90600f(props, ref) {
392
400
  let { onClose: onClose , shouldCloseOnBlur: shouldCloseOnBlur , isOpen: isOpen , isDismissable: isDismissable = false , isKeyboardDismissDisabled: isKeyboardDismissDisabled = false , shouldCloseOnInteractOutside: shouldCloseOnInteractOutside } = props;
@@ -439,6 +447,10 @@ function $a11501f3d1d39e6c$export$ea8f71083e90600f(props, ref) {
439
447
  let { focusWithinProps: focusWithinProps } = $k7QOs$useFocusWithin({
440
448
  isDisabled: !shouldCloseOnBlur,
441
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;
442
454
  if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.relatedTarget)) onClose();
443
455
  }
444
456
  });
@@ -1042,6 +1054,7 @@ function $86ea4cb521eb2e37$export$2317d149ed6f78c4(props) {
1042
1054
  */ // Keeps a ref count of all hidden elements. Added to when hiding an element, and
1043
1055
  // subtracted from when showing it again. When it reaches zero, aria-hidden is removed.
1044
1056
  let $5e3802645cc19319$var$refCountMap = new WeakMap();
1057
+ let $5e3802645cc19319$var$observerStack = [];
1045
1058
  function $5e3802645cc19319$export$1c3ebcada18427bf(targets, root = document.body) {
1046
1059
  let visibleNodes = new Set(targets);
1047
1060
  let hiddenNodes = new Set();
@@ -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,6 +1131,11 @@ 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);
1106
1139
  };
1107
1140
  }
1108
1141
 
@@ -1112,22 +1145,38 @@ function $5e3802645cc19319$export$1c3ebcada18427bf(targets, root = document.body
1112
1145
 
1113
1146
 
1114
1147
 
1148
+
1115
1149
  function $f2f8a6077418541e$export$542a6fd13ac93354(props, state) {
1116
- let { triggerRef: triggerRef , popoverRef: popoverRef , isNonModal: isNonModal , ...otherProps } = props;
1117
- let { overlayProps: overlayProps } = $a11501f3d1d39e6c$export$ea8f71083e90600f({
1150
+ let { triggerRef: triggerRef , popoverRef: popoverRef , isNonModal: isNonModal , isKeyboardDismissDisabled: isKeyboardDismissDisabled , ...otherProps } = props;
1151
+ let { overlayProps: overlayProps , underlayProps: underlayProps } = $a11501f3d1d39e6c$export$ea8f71083e90600f({
1118
1152
  isOpen: state.isOpen,
1119
1153
  onClose: state.close,
1120
1154
  shouldCloseOnBlur: true,
1121
- isDismissable: true
1155
+ isDismissable: !isNonModal,
1156
+ isKeyboardDismissDisabled: isKeyboardDismissDisabled
1122
1157
  }, popoverRef);
1123
- let { overlayProps: positionProps , arrowProps: arrowProps } = $2a41e45df1593e64$export$d39e1813b3bdd0e1({
1158
+ let { overlayProps: positionProps , arrowProps: arrowProps , placement: placement } = $2a41e45df1593e64$export$d39e1813b3bdd0e1({
1124
1159
  ...otherProps,
1125
1160
  targetRef: triggerRef,
1126
1161
  overlayRef: popoverRef,
1127
- isOpen: state.isOpen
1162
+ isOpen: state.isOpen,
1163
+ onClose: null
1128
1164
  });
1129
- $k7QOs$useEffect(()=>{
1130
- if (state.isOpen && !isNonModal) return $5e3802645cc19319$export$1c3ebcada18427bf([
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([
1131
1180
  popoverRef.current
1132
1181
  ]);
1133
1182
  }, [
@@ -1137,7 +1186,9 @@ function $f2f8a6077418541e$export$542a6fd13ac93354(props, state) {
1137
1186
  ]);
1138
1187
  return {
1139
1188
  popoverProps: $k7QOs$mergeProps(overlayProps, positionProps),
1140
- arrowProps: arrowProps
1189
+ arrowProps: arrowProps,
1190
+ underlayProps: underlayProps,
1191
+ placement: placement
1141
1192
  };
1142
1193
  }
1143
1194
 
@@ -1151,14 +1202,22 @@ function $f2f8a6077418541e$export$542a6fd13ac93354(props, state) {
1151
1202
 
1152
1203
 
1153
1204
 
1154
- const $337b884510726a0d$var$OverlayContext = /*#__PURE__*/ $k7QOs$react.createContext(null);
1205
+ const $337b884510726a0d$export$a2200b96afd16271 = /*#__PURE__*/ $k7QOs$react.createContext(null);
1155
1206
  function $337b884510726a0d$export$c6fdb837b070b4ff(props) {
1156
1207
  let isSSR = $k7QOs$useIsSSR();
1157
1208
  let { portalContainer: portalContainer = isSSR ? null : document.body } = props;
1158
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
+ ]);
1159
1218
  if (!portalContainer) return null;
1160
- let contents = /*#__PURE__*/ $k7QOs$react.createElement($337b884510726a0d$var$OverlayContext.Provider, {
1161
- value: setContain
1219
+ let contents = /*#__PURE__*/ $k7QOs$react.createElement($337b884510726a0d$export$a2200b96afd16271.Provider, {
1220
+ value: contextValue
1162
1221
  }, /*#__PURE__*/ $k7QOs$react.createElement($k7QOs$FocusScope, {
1163
1222
  restoreFocus: true,
1164
1223
  contain: contain
@@ -1166,7 +1225,8 @@ function $337b884510726a0d$export$c6fdb837b070b4ff(props) {
1166
1225
  return(/*#__PURE__*/ $k7QOs$reactdom.createPortal(contents, portalContainer));
1167
1226
  }
1168
1227
  function $337b884510726a0d$export$14c98a7594375490() {
1169
- let setContain = $k7QOs$useContext($337b884510726a0d$var$OverlayContext);
1228
+ let ctx = $k7QOs$useContext($337b884510726a0d$export$a2200b96afd16271);
1229
+ let setContain = ctx === null || ctx === void 0 ? void 0 : ctx.setContain;
1170
1230
  $k7QOs$useLayoutEffect(()=>{
1171
1231
  setContain === null || setContain === void 0 ? void 0 : setContain(true);
1172
1232
  }, [