File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ export default class Popup extends Component {
3636 zIndexWasSynced = false
3737
3838 triggerRef = React . createRef ( )
39+ elementRef = React . createRef ( )
3940
4041 static getDerivedStateFromProps ( props , state ) {
4142 if ( state . closed || state . disabled ) return { }
@@ -101,6 +102,12 @@ export default class Popup extends Component {
101102 }
102103
103104 hideOnScroll = ( e ) => {
105+ // Do not hide the popup when scroll comes from inside the popup
106+ // https://github.com/Semantic-Org/Semantic-UI-React/issues/4305
107+ if ( _ . isElement ( e . target ) && this . elementRef . current . contains ( e . target ) ) {
108+ return
109+ }
110+
104111 debug ( 'hideOnScroll()' )
105112 this . setState ( { closed : true } )
106113
@@ -179,7 +186,7 @@ export default class Popup extends Component {
179186 }
180187
181188 const innerElement = (
182- < ElementType { ...contentRestProps } className = { classes } style = { styles } >
189+ < ElementType { ...contentRestProps } className = { classes } style = { styles } ref = { this . elementRef } >
183190 { childrenUtils . isNil ( children ) ? (
184191 < >
185192 { PopupHeader . create ( header , { autoGenerateKey : false } ) }
Original file line number Diff line number Diff line change @@ -162,6 +162,24 @@ describe('Popup', () => {
162162 onClose . should . have . been . calledOnce ( )
163163 onClose . should . have . been . calledWithMatch ( { } , { content : 'foo' , onClose, trigger } )
164164 } )
165+
166+ it ( 'not hide on scroll from inside a popup' , ( ) => {
167+ const onClose = sandbox . spy ( )
168+ const child = < div data-child />
169+
170+ wrapperMount (
171+ < Popup hideOnScroll onClose = { onClose } trigger = { trigger } >
172+ { child }
173+ </ Popup > ,
174+ )
175+ wrapper . find ( 'button' ) . simulate ( 'click' )
176+
177+ domEvent . scroll ( document . querySelector ( '[data-child]' ) )
178+ onClose . should . not . have . been . called ( )
179+
180+ domEvent . scroll ( window )
181+ onClose . should . have . been . calledOnce ( )
182+ } )
165183 } )
166184
167185 describe ( 'hoverable' , ( ) => {
You can’t perform that action at this time.
0 commit comments