Popover relocate() fixes

This commit is contained in:
Juan Ferrer 2019-04-11 11:54:34 +02:00
parent 353167734e
commit faa0dc2b8d
1 changed files with 7 additions and 7 deletions

View File

@ -120,7 +120,6 @@ export default class Popover extends Component {
if (!(this.parent && this._shown)) return;
let margin = 10;
let scrollbarSize = 10;
let style = this.popover.style;
style.width = '';
@ -135,11 +134,12 @@ export default class Popover extends Component {
let arrowRect = this.arrow.getBoundingClientRect();
let clamp = (value, min, max) => Math.min(Math.max(value, min), max);
let arrowHeight = Math.sqrt(Math.pow(arrowRect.height, 2) * 2) / 2;
let arrowHeight = Math.floor(arrowRect.height / 2);
let arrowOffset = arrowHeight + margin / 2;
let endMargin = margin + scrollbarSize;
let maxRight = window.innerWidth - endMargin;
let maxBottom = window.innerHeight - endMargin;
let docEl = document.documentElement;
let maxRight = Math.min(window.innerWidth, docEl.clientWidth) - margin;
let maxBottom = Math.min(window.innerHeight, docEl.clientHeight) - margin;
let maxWith = maxRight - margin;
let maxHeight = maxBottom - margin - arrowHeight;
@ -149,9 +149,9 @@ export default class Popover extends Component {
let left = parentRect.left + parentRect.width / 2 - width / 2;
left = clamp(left, margin, maxRight - width);
let top = parentRect.top + parentRect.height + arrowHeight;
let top = parentRect.top + parentRect.height + arrowOffset;
let showTop = top + height > maxBottom;
if (showTop) top = parentRect.top - height - arrowHeight;
if (showTop) top = parentRect.top - height - arrowOffset;
top = Math.max(top, margin);
if (showTop)