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

Function getOffset

lib/core/useVirtualizer.ts:430–473  ·  view source on GitHub ↗
({
        clamp,
        containerScrollOffset,
        containerSize,
        padding
      }: {
        clamp: boolean;
        containerScrollOffset: number;
        containerSize: number;
        padding: { end: number; start: number };
      })

Source from the content-addressed store, hash-verified

428 // Like the browser's scrollIntoView, respect the scrolled element's CSS scroll-padding
429 // (e.g. so that items aren't aligned underneath a sticky header)
430 const getOffset = ({
431 clamp,
432 containerScrollOffset,
433 containerSize,
434 padding
435 }: {
436 clamp: boolean;
437 containerScrollOffset: number;
438 containerSize: number;
439 padding: { end: number; start: number };
440 }) => {
441 if (padding.start === 0 && padding.end === 0) {
442 return getOffsetForIndex({
443 align,
444 cachedBounds,
445 clamp,
446 containerScrollOffset,
447 containerSize,
448 index,
449 itemCount,
450 itemSize
451 });
452 }
453
454 // Align the item within the padded region of the viewport, then convert back to a scroll offset
455 const offset =
456 getOffsetForIndex({
457 align,
458 cachedBounds,
459 clamp: false,
460 containerScrollOffset: containerScrollOffset + padding.start,
461 containerSize: Math.max(
462 0,
463 containerSize - padding.start - padding.end
464 ),
465 index,
466 itemCount,
467 itemSize
468 }) - padding.start;
469
470 return clamp
471 ? Math.max(0, Math.min(getEstimatedSize() - containerSize, offset))
472 : offset;
473 };
474
475 if (
476 isScrollElementMode &&

Callers 1

useVirtualizerFunction · 0.85

Calls 2

getOffsetForIndexFunction · 0.90
getEstimatedSizeFunction · 0.90

Tested by

no test coverage detected