MCPcopy Create free account
hub / github.com/bvaughn/react-window / adjustScrollOffsetForRtl

Function adjustScrollOffsetForRtl

lib/utils/adjustScrollOffsetForRtl.ts:4–37  ·  view source on GitHub ↗
({
  containerElement,
  direction,
  isRtl,
  scrollOffset
}: {
  containerElement: HTMLElement | null;
  direction: Direction;
  isRtl: boolean;
  scrollOffset: number;
})

Source from the content-addressed store, hash-verified

2import { getRTLOffsetType } from "./getRTLOffsetType";
3
4export 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 (
21 getRTLOffsetType(false, containerElement?.ownerDocument ?? document)
22 ) {
23 case "negative": {
24 return -scrollOffset;
25 }
26 case "positive-descending": {
27 if (containerElement) {
28 const { clientWidth, scrollWidth } = containerElement;
29 return scrollWidth - clientWidth - scrollOffset;
30 }
31 break;
32 }
33 }
34 }
35 }
36 return scrollOffset;
37}

Callers 3

useVirtualizerFunction · 0.90
onScrollFunction · 0.90

Calls 1

getRTLOffsetTypeFunction · 0.90

Tested by

no test coverage detected