Commit f262ad7 1 parent 695b9de commit f262ad7 Copy full SHA for f262ad7
File tree 1 file changed +7
-3
lines changed
1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -76,10 +76,14 @@ export function setDefinitionPosition(
76
76
const { left : definitionParentLeft } = definitionParent . getBoundingClientRect ( ) ;
77
77
78
78
// 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 ;
82
81
82
+ const definitionOutOfScreenOnLeft = definitionLeftCoordinate - definitionWidth < 0 ;
83
+ const definitionOutOfScreenOnRight = definitionRightCoordinate > document . body . clientWidth ;
84
+
85
+ const isAlignSwapped = definitionOutOfScreenOnRight || document . dir === "rtl" ;
86
+ const fitDefinitionDocument = isAlignSwapped && ! definitionOutOfScreenOnLeft ? definitionWidth - termWidth : 0 ;
83
87
const customHeaderTop = getCoords ( definitionParent ) . top - definitionParent . offsetTop ;
84
88
85
89
definitionElement . style . top =
You can’t perform that action at this time.
0 commit comments