Skip to content

Commit 04afecf

Browse files
JeikZimRuslan Bagautdinov
and
Ruslan Bagautdinov
authored
fix: terms extend beyond right edge of screen (#447)
Fixed a bug where the term pop-up would extend beyond the edge of the screen on mobile devices. If the pop-up window goes beyond the right edge of the screen (on mobile devices), then the pop-up window is shifted to the left by as many pixels as it went beyond the screen and plus 5 pixels ---------------------------------------------------------------------------------------------------- Co-authored-by: Ruslan Bagautdinov <[email protected]>
1 parent 46024fc commit 04afecf

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/js/term/utils.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,21 @@ export function setDefinitionPosition(
8686
const fitDefinitionDocument =
8787
isAlignSwapped && !definitionOutOfScreenOnLeft ? definitionWidth - termWidth : 0;
8888
const customHeaderTop = getCoords(definitionParent).top - definitionParent.offsetTop;
89+
const offsetRight = 5;
90+
const shiftLeft = definitionOutOfScreenOnRight
91+
? definitionRightCoordinate - document.body.clientWidth + offsetRight
92+
: 0;
93+
const offsetLeft =
94+
getCoords(termElement).left -
95+
definitionParentLeft +
96+
definitionParent.offsetLeft -
97+
fitDefinitionDocument;
98+
99+
const isShiftLeftNeeded = offsetLeft + definitionWidth >= document.body.clientWidth;
89100

90101
definitionElement.style.top =
91102
Number(getCoords(termElement).top + offsetTop - customHeaderTop) + 'px';
92-
definitionElement.style.left =
93-
Number(
94-
getCoords(termElement).left -
95-
definitionParentLeft +
96-
definitionParent.offsetLeft -
97-
fitDefinitionDocument,
98-
) + 'px';
103+
definitionElement.style.left = Number(offsetLeft - (isShiftLeftNeeded ? shiftLeft : 0)) + 'px';
99104
}
100105

101106
function termOnResize() {

0 commit comments

Comments
 (0)