Skip to content

Commit

Permalink
feat(plugins/terms): rtl support (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
martyanovandrey authored Dec 22, 2023
1 parent 4042559 commit d2964aa
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/js/term/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,15 @@ export function setDefinitionPosition(
const {left: definitionParentLeft} = definitionParent.getBoundingClientRect();

// If definition not fit document change base alignment
const definitionRightCoordinate = definitionWidth + Number(getCoords(termElement).left);
const fitDefinitionDocument =
document.body.clientWidth > definitionRightCoordinate ? 0 : definitionWidth - termWidth;
const definitionLeftCoordinate = Number(getCoords(termElement).left);
const definitionRightCoordinate = definitionWidth + definitionLeftCoordinate;

const definitionOutOfScreenOnLeft = definitionLeftCoordinate - definitionWidth < 0;
const definitionOutOfScreenOnRight = definitionRightCoordinate > document.body.clientWidth;

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

definitionElement.style.top =
Expand Down

0 comments on commit d2964aa

Please sign in to comment.