@@ -140,7 +140,7 @@ export function useOverlayPosition(props: AriaPositionProps): PositionAria {
140
140
} , [ isOpen ] ) ;
141
141
142
142
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 ) {
144
144
return ;
145
145
}
146
146
@@ -153,7 +153,7 @@ export function useOverlayPosition(props: AriaPositionProps): PositionAria {
153
153
// so it can be restored after repositioning. This way if the overlay height
154
154
// changes, the focused element appears to stay in the same position.
155
155
let anchor : ScrollAnchor | null = null ;
156
- if ( scrollRef . current . contains ( document . activeElement ) ) {
156
+ if ( scrollRef . current && scrollRef . current . contains ( document . activeElement ) ) {
157
157
let anchorRect = document . activeElement . getBoundingClientRect ( ) ;
158
158
let scrollRect = scrollRef . current . getBoundingClientRect ( ) ;
159
159
// 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 {
181
181
placement : translateRTL ( placement , direction ) ,
182
182
overlayNode : overlayRef . current ,
183
183
targetNode : targetRef . current ,
184
- scrollNode : scrollRef . current ,
184
+ scrollNode : scrollRef . current || overlayRef . current ,
185
185
padding : containerPadding ,
186
186
shouldFlip,
187
187
boundaryElement,
0 commit comments