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

Function getScrollPadding

lib/utils/scrollElement.ts:174–214  ·  view source on GitHub ↗
({
  direction,
  isRtl,
  scrollTarget,
  viewportSize
}: {
  direction: Direction;
  isRtl: boolean;
  scrollTarget: ScrollTarget;
  viewportSize: number;
})

Source from the content-addressed store, hash-verified

172 * Percentages are relative to the viewport size; other values (e.g. "auto") are treated as 0.
173 */
174export function getScrollPadding({
175 direction,
176 isRtl,
177 scrollTarget,
178 viewportSize
179}: {
180 direction: Direction;
181 isRtl: boolean;
182 scrollTarget: ScrollTarget;
183 viewportSize: number;
184}): { end: number; start: number } {
185 // The window's scroll padding is specified on the root element
186 const element = isWindow(scrollTarget)
187 ? scrollTarget.document.documentElement
188 : scrollTarget;
189 const style = getOwnerWindow(element).getComputedStyle(element);
190
191 const parse = (value: string | undefined) => {
192 const number = parseFloat(value ?? "");
193 if (!Number.isFinite(number) || number < 0) {
194 return 0;
195 } else if (value!.endsWith("px")) {
196 return number;
197 } else if (value!.endsWith("%")) {
198 return (number * viewportSize) / 100;
199 }
200 return 0;
201 };
202
203 if (direction === "vertical") {
204 return {
205 end: parse(style.scrollPaddingBottom),
206 start: parse(style.scrollPaddingTop)
207 };
208 }
209
210 // Horizontal RTL content starts at the right edge
211 const left = parse(style.scrollPaddingLeft);
212 const right = parse(style.scrollPaddingRight);
213 return isRtl ? { end: left, start: right } : { end: right, start: left };
214}

Callers 3

useVirtualizerFunction · 0.90
mockScrollPaddingFunction · 0.85

Calls 3

getOwnerWindowFunction · 0.90
isWindowFunction · 0.85
parseFunction · 0.85

Tested by

no test coverage detected