@@ -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