Popover relocate() fixes
This commit is contained in:
parent
353167734e
commit
faa0dc2b8d
|
@ -120,7 +120,6 @@ export default class Popover extends Component {
|
||||||
if (!(this.parent && this._shown)) return;
|
if (!(this.parent && this._shown)) return;
|
||||||
|
|
||||||
let margin = 10;
|
let margin = 10;
|
||||||
let scrollbarSize = 10;
|
|
||||||
|
|
||||||
let style = this.popover.style;
|
let style = this.popover.style;
|
||||||
style.width = '';
|
style.width = '';
|
||||||
|
@ -135,11 +134,12 @@ export default class Popover extends Component {
|
||||||
let arrowRect = this.arrow.getBoundingClientRect();
|
let arrowRect = this.arrow.getBoundingClientRect();
|
||||||
let clamp = (value, min, max) => Math.min(Math.max(value, min), max);
|
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 docEl = document.documentElement;
|
||||||
let maxRight = window.innerWidth - endMargin;
|
let maxRight = Math.min(window.innerWidth, docEl.clientWidth) - margin;
|
||||||
let maxBottom = window.innerHeight - endMargin;
|
let maxBottom = Math.min(window.innerHeight, docEl.clientHeight) - margin;
|
||||||
let maxWith = maxRight - margin;
|
let maxWith = maxRight - margin;
|
||||||
let maxHeight = maxBottom - margin - arrowHeight;
|
let maxHeight = maxBottom - margin - arrowHeight;
|
||||||
|
|
||||||
|
@ -149,9 +149,9 @@ export default class Popover extends Component {
|
||||||
let left = parentRect.left + parentRect.width / 2 - width / 2;
|
let left = parentRect.left + parentRect.width / 2 - width / 2;
|
||||||
left = clamp(left, margin, maxRight - width);
|
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;
|
let showTop = top + height > maxBottom;
|
||||||
if (showTop) top = parentRect.top - height - arrowHeight;
|
if (showTop) top = parentRect.top - height - arrowOffset;
|
||||||
top = Math.max(top, margin);
|
top = Math.max(top, margin);
|
||||||
|
|
||||||
if (showTop)
|
if (showTop)
|
||||||
|
|
Loading…
Reference in New Issue