Skip to content
Snippets Groups Projects
Commit 797a08ec authored by Allen Gilliland's avatar Allen Gilliland
Browse files

Merge pull request #1282 from metabase/popover_positioning_fix

Fix issue with popover position being computed relative to document instead of window
parents 5b0c5d1d b96427e3
No related branches found
No related tags found
No related merge requests found
......@@ -90,8 +90,20 @@ export default class Popover extends Component {
// compute the options for this attachment position then set it
let options = getAttachmentOptions(best, attachment);
this._setTetherOptions(tetherOptions, options);
// test to see how much of the popover is off-screen
// get bounds within *document*
let elementRect = Tether.Utils.getBounds(tetherOptions.element);
// get bounds within *window*
let doc = document.documentElement;
let left = (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0);
let top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
elementRect.top -= top;
elementRect.bottom += top;
elementRect.left -= left;
elementRect.right += left;
// test to see how much of the popover is off-screen
let offScreen = offscreenProps.map(prop => Math.min(elementRect[prop], 0)).reduce((a, b) => a + b);
// if none then we're done, otherwise check to see if it's the best option so far
if (offScreen === 0) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment