({
containerElement,
direction,
isRtl,
scrollOffset
}: {
containerElement: HTMLElement | null;
direction: Direction;
isRtl: boolean;
scrollOffset: number;
})
| 2 | import { getRTLOffsetType } from "./getRTLOffsetType"; |
| 3 | |
| 4 | export function adjustScrollOffsetForRtl({ |
| 5 | containerElement, |
| 6 | direction, |
| 7 | isRtl, |
| 8 | scrollOffset |
| 9 | }: { |
| 10 | containerElement: HTMLElement | null; |
| 11 | direction: Direction; |
| 12 | isRtl: boolean; |
| 13 | scrollOffset: number; |
| 14 | }) { |
| 15 | // TRICKY According to the spec, scrollLeft should be negative for RTL aligned elements. |
| 16 | // This is not the case for all browsers though (e.g. Chrome reports values as positive, measured relative to the left). |
| 17 | // So we need to determine which browser behavior we're dealing with, and mimic it. |
| 18 | if (direction === "horizontal") { |
| 19 | if (isRtl) { |
| 20 | switch (getRTLOffsetType()) { |
| 21 | case "negative": { |
| 22 | return -scrollOffset; |
| 23 | } |
| 24 | case "positive-descending": { |
| 25 | if (containerElement) { |
| 26 | const { clientWidth, scrollLeft, scrollWidth } = containerElement; |
| 27 | return scrollWidth - clientWidth - scrollLeft; |
| 28 | } |
| 29 | break; |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | return scrollOffset; |
| 35 | } |
no test coverage detected
searching dependent graphs…