@@ -508,10 +508,16 @@ function RemoteFunctions(config) {
508508 let topPos = offset . top - boxHeight - 6 ; // 6 for just some little space to breathe
509509 let leftPos = offset . left + elemBounds . width - boxWidth ;
510510
511+ // Check if the box would go off the top of the viewport
511512 if ( offset . top - boxHeight < 0 ) {
512513 topPos = offset . top + elemBounds . height + 6 ;
513514 }
514515
516+ // Check if the box would go off the left of the viewport
517+ if ( leftPos < 0 ) {
518+ leftPos = offset . left ;
519+ }
520+
515521 return { topPos : topPos , leftPos : leftPos } ;
516522 } ,
517523
@@ -715,7 +721,7 @@ function RemoteFunctions(config) {
715721 return false ;
716722 } ,
717723
718- _getBoxPosition : function ( boxHeight , overlap = false ) {
724+ _getBoxPosition : function ( boxDimensions , overlap = false ) {
719725 const elemBounds = this . element . getBoundingClientRect ( ) ;
720726 const offset = _screenOffset ( this . element ) ;
721727 let topPos = 0 ;
@@ -724,13 +730,23 @@ function RemoteFunctions(config) {
724730 if ( overlap ) {
725731 topPos = offset . top + 2 ;
726732 leftPos = offset . left + elemBounds . width + 6 ;
733+
734+ // Check if overlap position would go off the right of the viewport
735+ if ( leftPos + boxDimensions . width > window . innerWidth ) {
736+ leftPos = offset . left - boxDimensions . width - 6 ;
737+ }
727738 } else {
728- topPos = offset . top - boxHeight - 6 ; // 6 for just some little space to breathes
739+ topPos = offset . top - boxDimensions . height - 6 ; // 6 for just some little space to breathe
729740 leftPos = offset . left ;
730741
731- if ( offset . top - boxHeight < 0 ) {
742+ if ( offset . top - boxDimensions . height < 0 ) {
732743 topPos = offset . top + elemBounds . height + 6 ;
733744 }
745+
746+ // Check if the box would go off the right of the viewport
747+ if ( leftPos + boxDimensions . width > window . innerWidth ) {
748+ leftPos = window . innerWidth - boxDimensions . width - 10 ;
749+ }
734750 }
735751
736752 return { topPos : topPos , leftPos : leftPos } ;
@@ -824,15 +840,15 @@ function RemoteFunctions(config) {
824840 height : boxElement . getBoundingClientRect ( ) . height ,
825841 width : boxElement . getBoundingClientRect ( ) . width
826842 } ;
827- const nodeInfoBoxPos = this . _getBoxPosition ( nodeInfoBoxDimensions . height ) ;
843+ const nodeInfoBoxPos = this . _getBoxPosition ( nodeInfoBoxDimensions , false ) ;
828844
829845 boxElement . style . left = nodeInfoBoxPos . leftPos + 'px' ;
830846 boxElement . style . top = nodeInfoBoxPos . topPos + 'px' ;
831847
832848 if ( this . isFromClick ) {
833849 const isBoxOverlapping = this . _checkOverlap ( nodeInfoBoxPos , nodeInfoBoxDimensions ) ;
834850 if ( isBoxOverlapping ) {
835- const newPos = this . _getBoxPosition ( nodeInfoBoxDimensions . height , true ) ;
851+ const newPos = this . _getBoxPosition ( nodeInfoBoxDimensions , true ) ;
836852 boxElement . style . left = newPos . leftPos + 'px' ;
837853 boxElement . style . top = newPos . topPos + 'px' ;
838854 }
0 commit comments