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