@react-aria/overlays 3.0.0-nightly.1979 → 3.0.0-nightly.1985

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.
@@ -115,20 +115,26 @@ export function useOverlayPosition(props: AriaPositionProps): PositionAria {
115
115
  return;
116
116
  }
117
117
 
118
- setPosition(
119
- calculatePosition({
120
- placement: translateRTL(placement, direction),
121
- overlayNode: overlayRef.current,
122
- targetNode: targetRef.current,
123
- scrollNode: scrollRef.current,
124
- padding: containerPadding,
125
- shouldFlip,
126
- boundaryElement,
127
- offset,
128
- crossOffset,
129
- maxHeight
130
- })
131
- );
118
+ let position = calculatePosition({
119
+ placement: translateRTL(placement, direction),
120
+ overlayNode: overlayRef.current,
121
+ targetNode: targetRef.current,
122
+ scrollNode: scrollRef.current,
123
+ padding: containerPadding,
124
+ shouldFlip,
125
+ boundaryElement,
126
+ offset,
127
+ crossOffset,
128
+ maxHeight
129
+ });
130
+
131
+ // Modify overlay styles directly so positioning happens immediately without the need of a second render
132
+ // This is so we don't have to delay autoFocus scrolling or delay applying preventScroll for popovers
133
+ Object.keys(position.position).forEach(key => (overlayRef.current as HTMLElement).style[key] = position.position[key] + 'px');
134
+ (overlayRef.current as HTMLElement).style.maxHeight = position.maxHeight != null ? position.maxHeight + 'px' : undefined;
135
+
136
+ // Trigger a set state for a second render anyway for arrow positioning
137
+ setPosition(position);
132
138
  // eslint-disable-next-line react-hooks/exhaustive-deps
133
139
  }, deps);
134
140
 
package/src/usePopover.ts CHANGED
@@ -16,7 +16,7 @@ import {DOMAttributes} from '@react-types/shared';
16
16
  import {mergeProps, useLayoutEffect} from '@react-aria/utils';
17
17
  import {OverlayTriggerState} from '@react-stately/overlays';
18
18
  import {PlacementAxis} from '@react-types/overlays';
19
- import {RefObject, useState} from 'react';
19
+ import {RefObject} from 'react';
20
20
  import {useOverlay} from './useOverlay';
21
21
  import {usePreventScroll} from './usePreventScroll';
22
22
 
@@ -92,18 +92,8 @@ export function usePopover(props: AriaPopoverProps, state: OverlayTriggerState):
92
92
  onClose: null
93
93
  });
94
94
 
95
- // Delay preventing scroll until popover is positioned to avoid extra scroll padding.
96
- // This requires a layout effect so that positioning has been committed to the DOM
97
- // by the time usePreventScroll measures the element.
98
- let [isPositioned, setPositioned] = useState(false);
99
- useLayoutEffect(() => {
100
- if (!isNonModal && placement) {
101
- setPositioned(true);
102
- }
103
- }, [isNonModal, placement]);
104
-
105
95
  usePreventScroll({
106
- isDisabled: isNonModal || !isPositioned
96
+ isDisabled: isNonModal
107
97
  });
108
98
 
109
99
  useLayoutEffect(() => {