Skip to content

Commit f998292

Browse files
reidbarberLFDanLu
andauthored
fix initial flash when opening RAC Menu (#6740)
Co-authored-by: Daniel Lu <[email protected]>
1 parent 4d3d2ac commit f998292

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

packages/@react-aria/overlays/src/useOverlayPosition.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export function useOverlayPosition(props: AriaPositionProps): PositionAria {
140140
}, [isOpen]);
141141

142142
let updatePosition = useCallback(() => {
143-
if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !scrollRef.current || !boundaryElement) {
143+
if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !boundaryElement) {
144144
return;
145145
}
146146

@@ -153,7 +153,7 @@ export function useOverlayPosition(props: AriaPositionProps): PositionAria {
153153
// so it can be restored after repositioning. This way if the overlay height
154154
// changes, the focused element appears to stay in the same position.
155155
let anchor: ScrollAnchor | null = null;
156-
if (scrollRef.current.contains(document.activeElement)) {
156+
if (scrollRef.current && scrollRef.current.contains(document.activeElement)) {
157157
let anchorRect = document.activeElement.getBoundingClientRect();
158158
let scrollRect = scrollRef.current.getBoundingClientRect();
159159
// Anchor from the top if the offset is in the top half of the scrollable element,
@@ -181,7 +181,7 @@ export function useOverlayPosition(props: AriaPositionProps): PositionAria {
181181
placement: translateRTL(placement, direction),
182182
overlayNode: overlayRef.current,
183183
targetNode: targetRef.current,
184-
scrollNode: scrollRef.current,
184+
scrollNode: scrollRef.current || overlayRef.current,
185185
padding: containerPadding,
186186
shouldFlip,
187187
boundaryElement,

0 commit comments

Comments
 (0)