@react-aria/overlays 3.7.3 → 3.8.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.
@@ -58,7 +58,8 @@ interface PositionOpts {
58
58
  shouldFlip: boolean,
59
59
  boundaryElement: HTMLElement,
60
60
  offset: number,
61
- crossOffset: number
61
+ crossOffset: number,
62
+ maxHeight?: number
62
63
  }
63
64
 
64
65
  export interface PositionResult {
@@ -284,7 +285,8 @@ export function calculatePositionInternal(
284
285
  containerOffsetWithBoundary: Offset,
285
286
  offset: number,
286
287
  crossOffset: number,
287
- isContainerPositioned: boolean
288
+ isContainerPositioned: boolean,
289
+ userSetMaxHeight?: number
288
290
  ): PositionResult {
289
291
  let placementInfo = parsePlacement(placementInput);
290
292
  let {size, crossAxis, crossSize, placement, crossPlacement} = placementInfo;
@@ -332,6 +334,10 @@ export function calculatePositionInternal(
332
334
  padding
333
335
  );
334
336
 
337
+ if (userSetMaxHeight && userSetMaxHeight < maxHeight) {
338
+ maxHeight = userSetMaxHeight;
339
+ }
340
+
335
341
  overlaySize.height = Math.min(overlaySize.height, maxHeight);
336
342
 
337
343
  position = computePosition(childOffset, boundaryDimensions, overlaySize, placementInfo, normalizedOffset, crossOffset, containerOffsetWithBoundary, isContainerPositioned);
@@ -363,7 +369,8 @@ export function calculatePosition(opts: PositionOpts): PositionResult {
363
369
  shouldFlip,
364
370
  boundaryElement,
365
371
  offset,
366
- crossOffset
372
+ crossOffset,
373
+ maxHeight
367
374
  } = opts;
368
375
 
369
376
  let container = overlayNode.offsetParent || document.body;
@@ -398,6 +405,7 @@ export function calculatePosition(opts: PositionOpts): PositionResult {
398
405
  containerOffsetWithBoundary,
399
406
  offset,
400
407
  crossOffset,
401
- isContainerPositioned
408
+ isContainerPositioned,
409
+ maxHeight
402
410
  );
403
411
  }
@@ -42,7 +42,12 @@ interface AriaPositionProps extends PositionProps {
42
42
  */
43
43
  shouldUpdatePosition?: boolean,
44
44
  /** Handler that is called when the overlay should close. */
45
- onClose?: () => void
45
+ onClose?: () => void,
46
+ /**
47
+ * The maxHeight specified for the overlay element.
48
+ * By default, it will take all space up to the current viewport height.
49
+ */
50
+ maxHeight?: number
46
51
  }
47
52
 
48
53
  interface PositionAria {
@@ -77,7 +82,8 @@ export function useOverlayPosition(props: AriaPositionProps): PositionAria {
77
82
  crossOffset = 0,
78
83
  shouldUpdatePosition = true,
79
84
  isOpen = true,
80
- onClose
85
+ onClose,
86
+ maxHeight
81
87
  } = props;
82
88
  let [position, setPosition] = useState<PositionResult>({
83
89
  position: {},
@@ -99,7 +105,8 @@ export function useOverlayPosition(props: AriaPositionProps): PositionAria {
99
105
  offset,
100
106
  crossOffset,
101
107
  isOpen,
102
- direction
108
+ direction,
109
+ maxHeight
103
110
  ];
104
111
 
105
112
  let updatePosition = useCallback(() => {
@@ -117,7 +124,8 @@ export function useOverlayPosition(props: AriaPositionProps): PositionAria {
117
124
  shouldFlip,
118
125
  boundaryElement,
119
126
  offset,
120
- crossOffset
127
+ crossOffset,
128
+ maxHeight
121
129
  })
122
130
  );
123
131
  }, deps);