@@ -604,6 +604,7 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
604604 var node = _reactDom2 . default . findDOMNode ( this ) ;
605605
606606 var result = ( 0 , _getPosition2 . default ) ( currentEvent , currentTarget , node , place , effect , offset ) ;
607+
607608 if ( result . isNewState ) {
608609 // Switch to reverse placement
609610 return this . setState ( result . newState , function ( ) {
@@ -737,29 +738,28 @@ exports.default = function (e, target, node, place, effect, offset) {
737738
738739 // Judge if the tooltip has over the window(screen)
739740 var outsideVertical = function outsideVertical ( ) {
740- // Check for horazontal tooltip, if their vertical out of screen
741741 var result = false ;
742742 var newPlace = void 0 ;
743- if ( getTipOffsetTop ( 'left' ) < 0 && getTipOffsetBottom ( 'left' ) <= windowHeight ) {
743+ if ( getTipOffsetTop ( 'left' ) < 0 && getTipOffsetBottom ( 'left' ) <= windowHeight && getTipOffsetBottom ( 'bottom' ) <= windowHeight ) {
744744 result = true ;
745745 newPlace = 'bottom' ;
746- } else if ( getTipOffsetBottom ( 'left' ) > windowHeight && getTipOffsetTop ( 'left' ) >= 0 ) {
746+ } else if ( getTipOffsetBottom ( 'left' ) > windowHeight && getTipOffsetTop ( 'left' ) >= 0 && getTipOffsetTop ( 'top' ) >= 0 ) {
747747 result = true ;
748748 newPlace = 'top' ;
749749 }
750- if ( result && outsideHorizontal ( ) . result ) result = false ;
751750 return { result : result , newPlace : newPlace } ;
752751 } ;
753752 var outsideLeft = function outsideLeft ( ) {
754- // For horizontal tooltip, if vertical out of screen, change the vertical place
755-
756753 var _outsideVertical = outsideVertical ( ) ;
757754
758755 var result = _outsideVertical . result ;
759- var newPlace = _outsideVertical . newPlace ;
756+ var newPlace = _outsideVertical . newPlace ; // Deal with vertical as first priority
760757
758+ if ( result && outsideHorizontal ( ) . result ) {
759+ return { result : false } ; // No need to change, if change to vertical will out of space
760+ }
761761 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
763763 newPlace = 'right' ;
764764 }
765765 return { result : result , newPlace : newPlace } ;
@@ -770,6 +770,9 @@ exports.default = function (e, target, node, place, effect, offset) {
770770 var result = _outsideVertical2 . result ;
771771 var newPlace = _outsideVertical2 . newPlace ;
772772
773+ if ( result && outsideHorizontal ( ) . result ) {
774+ return { result : false } ; // No need to change, if change to vertical will out of space
775+ }
773776 if ( ! result && getTipOffsetRight ( 'right' ) > windowWidth && getTipOffsetLeft ( 'left' ) >= 0 ) {
774777 result = true ;
775778 newPlace = 'left' ;
@@ -780,15 +783,13 @@ exports.default = function (e, target, node, place, effect, offset) {
780783 var outsideHorizontal = function outsideHorizontal ( ) {
781784 var result = false ;
782785 var newPlace = void 0 ;
783- if ( getTipOffsetLeft ( 'top' ) < 0 && getTipOffsetRight ( 'top' ) <= windowWidth ) {
786+ if ( getTipOffsetLeft ( 'top' ) < 0 && getTipOffsetRight ( 'top' ) <= windowWidth && getTipOffsetRight ( 'right' ) <= windowWidth ) {
784787 result = true ;
785788 newPlace = 'right' ;
786- } else if ( getTipOffsetRight ( 'top' ) > windowWidth && getTipOffsetLeft ( 'top' ) >= 0 ) {
789+ } else if ( getTipOffsetRight ( 'top' ) > windowWidth && getTipOffsetLeft ( 'top' ) >= 0 && getTipOffsetLeft ( 'left' ) >= 0 ) {
787790 result = true ;
788791 newPlace = 'left' ;
789792 }
790-
791- if ( result && outsideVertical ( ) . result ) result = false ;
792793 return { result : result , newPlace : newPlace } ;
793794 } ;
794795 var outsideTop = function outsideTop ( ) {
@@ -797,6 +798,9 @@ exports.default = function (e, target, node, place, effect, offset) {
797798 var result = _outsideHorizontal . result ;
798799 var newPlace = _outsideHorizontal . newPlace ;
799800
801+ if ( result && outsideVertical ( ) . result ) {
802+ return { result : false } ;
803+ }
800804 if ( ! result && getTipOffsetTop ( 'top' ) < 0 && getTipOffsetBottom ( 'bottom' ) <= windowHeight ) {
801805 result = true ;
802806 newPlace = 'bottom' ;
@@ -809,6 +813,9 @@ exports.default = function (e, target, node, place, effect, offset) {
809813 var result = _outsideHorizontal2 . result ;
810814 var newPlace = _outsideHorizontal2 . newPlace ;
811815
816+ if ( result && outsideVertical ( ) . result ) {
817+ return { result : false } ;
818+ }
812819 if ( ! result && getTipOffsetBottom ( 'bottom' ) > windowHeight && getTipOffsetTop ( 'top' ) >= 0 ) {
813820 result = true ;
814821 newPlace = 'top' ;
0 commit comments