@@ -604,6 +604,7 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
604
604
var node = _reactDom2 . default . findDOMNode ( this ) ;
605
605
606
606
var result = ( 0 , _getPosition2 . default ) ( currentEvent , currentTarget , node , place , effect , offset ) ;
607
+
607
608
if ( result . isNewState ) {
608
609
// Switch to reverse placement
609
610
return this . setState ( result . newState , function ( ) {
@@ -737,29 +738,28 @@ exports.default = function (e, target, node, place, effect, offset) {
737
738
738
739
// Judge if the tooltip has over the window(screen)
739
740
var outsideVertical = function outsideVertical ( ) {
740
- // Check for horazontal tooltip, if their vertical out of screen
741
741
var result = false ;
742
742
var newPlace = void 0 ;
743
- if ( getTipOffsetTop ( 'left' ) < 0 && getTipOffsetBottom ( 'left' ) <= windowHeight ) {
743
+ if ( getTipOffsetTop ( 'left' ) < 0 && getTipOffsetBottom ( 'left' ) <= windowHeight && getTipOffsetBottom ( 'bottom' ) <= windowHeight ) {
744
744
result = true ;
745
745
newPlace = 'bottom' ;
746
- } else if ( getTipOffsetBottom ( 'left' ) > windowHeight && getTipOffsetTop ( 'left' ) >= 0 ) {
746
+ } else if ( getTipOffsetBottom ( 'left' ) > windowHeight && getTipOffsetTop ( 'left' ) >= 0 && getTipOffsetTop ( 'top' ) >= 0 ) {
747
747
result = true ;
748
748
newPlace = 'top' ;
749
749
}
750
- if ( result && outsideHorizontal ( ) . result ) result = false ;
751
750
return { result : result , newPlace : newPlace } ;
752
751
} ;
753
752
var outsideLeft = function outsideLeft ( ) {
754
- // For horizontal tooltip, if vertical out of screen, change the vertical place
755
-
756
753
var _outsideVertical = outsideVertical ( ) ;
757
754
758
755
var result = _outsideVertical . result ;
759
- var newPlace = _outsideVertical . newPlace ;
756
+ var newPlace = _outsideVertical . newPlace ; // Deal with vertical as first priority
760
757
758
+ if ( result && outsideHorizontal ( ) . result ) {
759
+ return { result : false } ; // No need to change, if change to vertical will out of space
760
+ }
761
761
if ( ! result && getTipOffsetLeft ( 'left' ) < 0 && getTipOffsetRight ( 'right' ) <= windowWidth ) {
762
- result = true ;
762
+ result = true ; // If vertical ok, but let out of side and right won't out of side
763
763
newPlace = 'right' ;
764
764
}
765
765
return { result : result , newPlace : newPlace } ;
@@ -770,6 +770,9 @@ exports.default = function (e, target, node, place, effect, offset) {
770
770
var result = _outsideVertical2 . result ;
771
771
var newPlace = _outsideVertical2 . newPlace ;
772
772
773
+ if ( result && outsideHorizontal ( ) . result ) {
774
+ return { result : false } ; // No need to change, if change to vertical will out of space
775
+ }
773
776
if ( ! result && getTipOffsetRight ( 'right' ) > windowWidth && getTipOffsetLeft ( 'left' ) >= 0 ) {
774
777
result = true ;
775
778
newPlace = 'left' ;
@@ -780,15 +783,13 @@ exports.default = function (e, target, node, place, effect, offset) {
780
783
var outsideHorizontal = function outsideHorizontal ( ) {
781
784
var result = false ;
782
785
var newPlace = void 0 ;
783
- if ( getTipOffsetLeft ( 'top' ) < 0 && getTipOffsetRight ( 'top' ) <= windowWidth ) {
786
+ if ( getTipOffsetLeft ( 'top' ) < 0 && getTipOffsetRight ( 'top' ) <= windowWidth && getTipOffsetRight ( 'right' ) <= windowWidth ) {
784
787
result = true ;
785
788
newPlace = 'right' ;
786
- } else if ( getTipOffsetRight ( 'top' ) > windowWidth && getTipOffsetLeft ( 'top' ) >= 0 ) {
789
+ } else if ( getTipOffsetRight ( 'top' ) > windowWidth && getTipOffsetLeft ( 'top' ) >= 0 && getTipOffsetLeft ( 'left' ) >= 0 ) {
787
790
result = true ;
788
791
newPlace = 'left' ;
789
792
}
790
-
791
- if ( result && outsideVertical ( ) . result ) result = false ;
792
793
return { result : result , newPlace : newPlace } ;
793
794
} ;
794
795
var outsideTop = function outsideTop ( ) {
@@ -797,6 +798,9 @@ exports.default = function (e, target, node, place, effect, offset) {
797
798
var result = _outsideHorizontal . result ;
798
799
var newPlace = _outsideHorizontal . newPlace ;
799
800
801
+ if ( result && outsideVertical ( ) . result ) {
802
+ return { result : false } ;
803
+ }
800
804
if ( ! result && getTipOffsetTop ( 'top' ) < 0 && getTipOffsetBottom ( 'bottom' ) <= windowHeight ) {
801
805
result = true ;
802
806
newPlace = 'bottom' ;
@@ -809,6 +813,9 @@ exports.default = function (e, target, node, place, effect, offset) {
809
813
var result = _outsideHorizontal2 . result ;
810
814
var newPlace = _outsideHorizontal2 . newPlace ;
811
815
816
+ if ( result && outsideVertical ( ) . result ) {
817
+ return { result : false } ;
818
+ }
812
819
if ( ! result && getTipOffsetBottom ( 'bottom' ) > windowHeight && getTipOffsetTop ( 'top' ) >= 0 ) {
813
820
result = true ;
814
821
newPlace = 'top' ;
0 commit comments