浏览代码

Move the hoverbox to fit on screen

Steven Silvester 8 年之前
父节点
当前提交
cb25b63fe3
共有 1 个文件被更改,包括 9 次插入1 次删除
  1. 9 1
      packages/apputils/src/hoverbox.ts

+ 9 - 1
packages/apputils/src/hoverbox.ts

@@ -160,7 +160,8 @@ namespace HoverBox {
 
     // Position the box horizontally.
     const offsetHorizontal = options.offset && options.offset.horizontal || 0;
-    const left = anchor.left + offsetHorizontal;
+    let left = anchor.left + offsetHorizontal;
+
     node.style.left = `${Math.ceil(left)}px`;
     node.style.width = 'auto';
 
@@ -169,5 +170,12 @@ namespace HoverBox {
       node.style.width = `${2 * node.offsetWidth - node.clientWidth}`;
       node.scrollTop = 0;
     }
+
+    // Move left to fit in the window.
+    let right = node.getBoundingClientRect().right;
+    if (right > window.innerWidth) {
+      left -= right - window.innerWidth;
+      node.style.left = `${Math.ceil(left)}px`;
+    }
   }
 }