1
1
/*!
2
- * reactjs-popup v1.3.1
2
+ * reactjs-popup v1.3.2
3
3
* (c) 2018-present Youssouf EL AZIZI <[email protected] >
4
4
* Released under the MIT License.
5
5
*/
@@ -326,6 +326,14 @@ function (_React$PureComponent) {
326
326
327
327
} ) ;
328
328
329
+ _defineProperty ( _assertThisInitialized ( _assertThisInitialized ( _this ) ) , "repositionOnResize" , function ( ) {
330
+ _this . setPosition ( ) ;
331
+ } ) ;
332
+
333
+ _defineProperty ( _assertThisInitialized ( _assertThisInitialized ( _this ) ) , "onEscape" , function ( e ) {
334
+ if ( e . key === "Escape" ) _this . closePopup ( ) ;
335
+ } ) ;
336
+
329
337
_defineProperty ( _assertThisInitialized ( _assertThisInitialized ( _this ) ) , "lockScroll" , function ( ) {
330
338
if ( _this . state . modal && _this . props . lockScroll ) document . getElementsByTagName ( "body" ) [ 0 ] . style . overflow = "hidden" ;
331
339
} ) ;
@@ -403,15 +411,17 @@ function (_React$PureComponent) {
403
411
} ) ;
404
412
405
413
_defineProperty ( _assertThisInitialized ( _assertThisInitialized ( _this ) ) , "setPosition" , function ( ) {
414
+ var _this$state = _this . state ,
415
+ modal = _this$state . modal ,
416
+ isOpen = _this$state . isOpen ;
417
+ if ( modal || ! isOpen ) return ;
406
418
var _this$props = _this . props ,
407
419
arrow = _this$props . arrow ,
408
420
position = _this$props . position ,
409
421
offsetX = _this$props . offsetX ,
410
422
offsetY = _this$props . offsetY ,
411
423
keepTooltipInside = _this$props . keepTooltipInside ,
412
424
arrowStyle = _this$props . arrowStyle ;
413
- var modal = _this . state . modal ;
414
- if ( modal ) return ;
415
425
416
426
var helper = _this . HelperEl . getBoundingClientRect ( ) ;
417
427
@@ -532,17 +542,18 @@ function (_React$PureComponent) {
532
542
_createClass ( Popup , [ {
533
543
key : "componentDidMount" ,
534
544
value : function componentDidMount ( ) {
535
- var _this2 = this ;
536
-
537
545
var _this$props5 = this . props ,
538
546
closeOnEscape = _this$props5 . closeOnEscape ,
539
- defaultOpen = _this$props5 . defaultOpen ;
547
+ defaultOpen = _this$props5 . defaultOpen ,
548
+ repositionOnResize = _this$props5 . repositionOnResize ;
540
549
if ( defaultOpen ) this . setPosition ( ) ;
541
550
542
551
if ( closeOnEscape ) {
543
- window . addEventListener ( "keyup" , function ( e ) {
544
- if ( e . key === "Escape" ) _this2 . closePopup ( ) ;
545
- } ) ;
552
+ window . addEventListener ( "keyup" , this . onEscape ) ;
553
+ }
554
+
555
+ if ( repositionOnResize ) {
556
+ window . addEventListener ( 'resize' , this . repositionOnResize ) ;
546
557
}
547
558
}
548
559
} , {
@@ -563,14 +574,25 @@ function (_React$PureComponent) {
563
574
value : function componentWillUnmount ( ) {
564
575
// kill any function to execute if the component is unmounted
565
576
clearTimeout ( this . timeOut ) ;
577
+ var _this$props6 = this . props ,
578
+ closeOnEscape = _this$props6 . closeOnEscape ,
579
+ repositionOnResize = _this$props6 . repositionOnResize ; // remove events listeners
580
+
581
+ if ( closeOnEscape ) {
582
+ window . removeEventListener ( "keyup" , this . onEscape ) ;
583
+ }
584
+
585
+ if ( repositionOnResize ) {
586
+ window . removeEventListener ( 'resize' , this . repositionOnResize ) ;
587
+ }
566
588
}
567
589
} , {
568
590
key : "render" ,
569
591
value : function render ( ) {
570
- var _this$props6 = this . props ,
571
- overlayStyle = _this$props6 . overlayStyle ,
572
- closeOnDocumentClick = _this$props6 . closeOnDocumentClick ,
573
- on = _this$props6 . on ;
592
+ var _this$props7 = this . props ,
593
+ overlayStyle = _this$props7 . overlayStyle ,
594
+ closeOnDocumentClick = _this$props7 . closeOnDocumentClick ,
595
+ on = _this$props7 . on ;
574
596
var modal = this . state . modal ;
575
597
var overlay = this . state . isOpen && ! ( on . indexOf ( "hover" ) >= 0 ) ;
576
598
var ovStyle = modal ? styles . overlay . modal : styles . overlay . tooltip ;
@@ -608,6 +630,7 @@ _defineProperty(Popup, "defaultProps", {
608
630
open : false ,
609
631
disabled : false ,
610
632
closeOnDocumentClick : true ,
633
+ repositionOnResize : true ,
611
634
closeOnEscape : true ,
612
635
on : [ "click" ] ,
613
636
contentStyle : { } ,
@@ -636,6 +659,7 @@ if (process.env.NODE_ENV !== "production") {
636
659
className : PropTypes . string ,
637
660
modal : PropTypes . bool ,
638
661
closeOnDocumentClick : PropTypes . bool ,
662
+ repositionOnResize : PropTypes . bool ,
639
663
disabled : PropTypes . bool ,
640
664
lockScroll : PropTypes . bool ,
641
665
offsetX : PropTypes . number ,
0 commit comments