Skip to content

Commit 38b0eb3

Browse files
feat(plugins/terms): rtl support
1 parent 695b9de commit 38b0eb3

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/js/term/utils.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,15 @@ export function setDefinitionPosition(
7676
const {left: definitionParentLeft} = definitionParent.getBoundingClientRect();
7777

7878
// If definition not fit document change base alignment
79-
const definitionRightCoordinate = definitionWidth + Number(getCoords(termElement).left);
80-
const fitDefinitionDocument =
81-
document.body.clientWidth > definitionRightCoordinate ? 0 : definitionWidth - termWidth;
79+
const definitionLeftCoordinate = Number(getCoords(termElement).left);
80+
const definitionRightCoordinate = definitionWidth + definitionLeftCoordinate;
81+
82+
const definitionOutOfScreenOnLeft = definitionLeftCoordinate - definitionWidth < 0;
83+
const definitionOutOfScreenOnRight = definitionRightCoordinate > document.body.clientWidth;
8284

85+
const isAlignSwapped = definitionOutOfScreenOnRight || document.dir === 'rtl';
86+
const fitDefinitionDocument =
87+
isAlignSwapped && !definitionOutOfScreenOnLeft ? definitionWidth - termWidth : 0;
8388
const customHeaderTop = getCoords(definitionParent).top - definitionParent.offsetTop;
8489

8590
definitionElement.style.top =

0 commit comments

Comments
 (0)