@@ -13,6 +13,7 @@ export interface Props<Strategy> {
13
13
onOpen ?: ( ) => void ;
14
14
onClose ?: ( ) => void ;
15
15
onShouldClose ?: ( ) => void ;
16
+ closeOnScroll ?: boolean ;
16
17
closeOnOutsideClick ?: boolean ;
17
18
closeOnKeyDown ?: ( event : KeyboardEvent ) => boolean ;
18
19
isOpen ?: boolean ;
@@ -127,6 +128,7 @@ class PositioningPortal<Strategy = Position> extends React.Component<
127
128
> {
128
129
public static defaultProps = {
129
130
isOpen : false ,
131
+ closeOnScroll : true ,
130
132
onOpen : noop ,
131
133
onClose : noop ,
132
134
onShouldClose : noop ,
@@ -185,9 +187,11 @@ class PositioningPortal<Strategy = Position> extends React.Component<
185
187
) ;
186
188
187
189
// Remove scroll event listeners
188
- this . state . scrollParents . forEach ( ( node ) =>
189
- node . removeEventListener ( 'scroll' , this . close , false )
190
- ) ;
190
+ if ( this . props . closeOnScroll ) {
191
+ this . state . scrollParents . forEach ( ( node ) =>
192
+ node . removeEventListener ( 'scroll' , this . close , false )
193
+ ) ;
194
+ }
191
195
}
192
196
193
197
public close = ( ) => {
@@ -300,12 +304,15 @@ class PositioningPortal<Strategy = Position> extends React.Component<
300
304
if ( parentDom && parentDom . nodeType === Node . ELEMENT_NODE ) {
301
305
const parentRect = ( parentDom as Element ) . getBoundingClientRect ( ) ;
302
306
303
- let scrollParents = [ ] ;
307
+ let scrollParents : ( HTMLElement | Window ) [ ] = [ ] ;
308
+
304
309
// Register scroll listener on all scrollable parents to close the portal on scroll
305
- scrollParents = getScrollParents ( parentDom as HTMLElement ) ;
306
- scrollParents . forEach ( ( node ) =>
307
- node . addEventListener ( 'scroll' , this . close , false )
308
- ) ;
310
+ if ( this . props . closeOnScroll ) {
311
+ scrollParents = getScrollParents ( parentDom as HTMLElement ) ;
312
+ scrollParents . forEach ( ( node ) =>
313
+ node . addEventListener ( 'scroll' , this . close , false )
314
+ ) ;
315
+ }
309
316
310
317
this . setState (
311
318
{
0 commit comments