Skip to content

Commit e8bc9c6

Browse files
committed
fix: boxes overlapping each other
1 parent e3945a1 commit e8bc9c6

File tree

1 file changed

+58
-10
lines changed

1 file changed

+58
-10
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -683,15 +683,51 @@ function RemoteFunctions(config) {
683683
}
684684

685685
NodeInfoBox.prototype = {
686-
_getBoxPosition: function(boxHeight) {
686+
_checkOverlap: function(nodeInfoBoxPos, nodeInfoBoxDimensions) {
687+
if (_nodeMoreOptionsBox && _nodeMoreOptionsBox._shadow) {
688+
const moreOptionsBoxElement = _nodeMoreOptionsBox._shadow.querySelector('.phoenix-more-options-box');
689+
if (moreOptionsBoxElement) {
690+
const moreOptionsBoxRect = moreOptionsBoxElement.getBoundingClientRect();
691+
692+
const infoBox = {
693+
left: nodeInfoBoxPos.leftPos,
694+
top: nodeInfoBoxPos.topPos,
695+
right: nodeInfoBoxPos.leftPos + nodeInfoBoxDimensions.width,
696+
bottom: nodeInfoBoxPos.topPos + nodeInfoBoxDimensions.height
697+
};
698+
699+
const moreOptionsBox = {
700+
left: moreOptionsBoxRect.left,
701+
top: moreOptionsBoxRect.top,
702+
right: moreOptionsBoxRect.right,
703+
bottom: moreOptionsBoxRect.bottom
704+
};
705+
706+
return !(infoBox.right < moreOptionsBox.left ||
707+
moreOptionsBox.right < infoBox.left ||
708+
infoBox.bottom < moreOptionsBox.top ||
709+
moreOptionsBox.bottom < infoBox.top);
710+
}
711+
}
712+
return false;
713+
},
714+
715+
_getBoxPosition: function(boxHeight, overlap = false) {
687716
const elemBounds = this.element.getBoundingClientRect();
688717
const offset = _screenOffset(this.element);
718+
let topPos = 0;
719+
let leftPos = 0;
689720

690-
let topPos = offset.top - boxHeight - 6; // 6 for just some little space to breathes
691-
let leftPos = offset.left;
721+
if (overlap) {
722+
topPos = offset.top + 2;
723+
leftPos = offset.left + elemBounds.width + 6;
724+
} else {
725+
topPos = offset.top - boxHeight - 6; // 6 for just some little space to breathes
726+
leftPos = offset.left;
692727

693-
if (offset.top - boxHeight < 0) {
694-
topPos = offset.top + elemBounds.height + 6;
728+
if (offset.top - boxHeight < 0) {
729+
topPos = offset.top + elemBounds.height + 6;
730+
}
695731
}
696732

697733
return {topPos: topPos, leftPos: leftPos};
@@ -781,11 +817,23 @@ function RemoteFunctions(config) {
781817
// get the actual rendered height of the box and then we reposition it to the actual place
782818
const boxElement = this._shadow.querySelector('.phoenix-node-info-box');
783819
if (boxElement) {
784-
const nodeInfoBoxHeight = boxElement.getBoundingClientRect().height;
785-
const pos = this._getBoxPosition(nodeInfoBoxHeight);
786-
787-
boxElement.style.left = pos.leftPos + 'px';
788-
boxElement.style.top = pos.topPos + 'px';
820+
const nodeInfoBoxDimensions = {
821+
height: boxElement.getBoundingClientRect().height,
822+
width: boxElement.getBoundingClientRect().width
823+
};
824+
const nodeInfoBoxPos = this._getBoxPosition(nodeInfoBoxDimensions.height);
825+
826+
boxElement.style.left = nodeInfoBoxPos.leftPos + 'px';
827+
boxElement.style.top = nodeInfoBoxPos.topPos + 'px';
828+
829+
if(this.isFromClick) {
830+
const isBoxOverlapping = this._checkOverlap(nodeInfoBoxPos, nodeInfoBoxDimensions);
831+
if(isBoxOverlapping) {
832+
const newPos = this._getBoxPosition(nodeInfoBoxDimensions.height, true);
833+
boxElement.style.left = newPos.leftPos + 'px';
834+
boxElement.style.top = newPos.topPos + 'px';
835+
}
836+
}
789837
}
790838
},
791839

0 commit comments

Comments
 (0)