MCPcopy
hub / github.com/bvaughn/react-window / adjustScrollOffsetForRtl

Function adjustScrollOffsetForRtl

lib/utils/adjustScrollOffsetForRtl.ts:4–35  ·  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 (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}

Callers 2

useVirtualizerFunction · 0.90
onScrollFunction · 0.90

Calls 1

getRTLOffsetTypeFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…