@@ -285,7 +285,17 @@ function RemoteFunctions(config) {
285285 this . body = window . document . createElement ( "div" ) ;
286286 this . body . style . setProperty ( "z-index" , 2147483647 ) ;
287287 this . body . style . setProperty ( "position" , "fixed" ) ;
288- this . body . style . setProperty ( "left" , elemBounds . left + ( elemBounds . width - 40 ) + "px" ) ;
288+
289+ // the more options box width
290+ const boxWidth = 82 + 16 ; // 82px width + 8px padding on each side
291+ let leftPos = elemBounds . left + ( elemBounds . width - 40 ) ; // the potential left position
292+ // make sure that box wouldn't go out of the viewport
293+ const viewportWidth = window . innerWidth || document . documentElement . clientWidth ;
294+ if ( leftPos + boxWidth > viewportWidth ) {
295+ leftPos = viewportWidth - boxWidth ;
296+ }
297+
298+ this . body . style . setProperty ( "left" , leftPos + "px" ) ;
289299 this . body . style . setProperty (
290300 "top" ,
291301 // if there's not enough space to show the box above the element,
@@ -302,7 +312,7 @@ function RemoteFunctions(config) {
302312 this . body . style . setProperty ( "padding" , "5px 8px" ) ;
303313 this . body . style . setProperty ( "box-shadow" , "0 2px 5px rgba(0,0,0,0.2)" ) ;
304314 this . body . style . setProperty ( "max-width" , "82px" ) ;
305- this . body . style . setProperty ( "width" , "82px" ) ;
315+ this . body . style . setProperty ( "width" , "82px" ) ; // if changing this, also update the boxWidth variable
306316
307317 const ICONS = {
308318 arrowUp : `<svg viewBox="0 0 24 24" fill="currentColor">
0 commit comments