MCPcopy Create free account
hub / github.com/bvaughn/react-virtualized / getDimensions

Function getDimensions

lib/utils/scrollElement/dimensions.ts:23–38  ·  view source on GitHub ↗
(
  scrollElement: ResolvedScrollElement
)

Source from the content-addressed store, hash-verified

21const getBoundingBox = (element: Element) => element.getBoundingClientRect();
22
23export function getDimensions(
24 scrollElement: ResolvedScrollElement
25): Dimensions {
26 if (isWindow(scrollElement)) {
27 const { innerHeight, innerWidth } = window;
28 return {
29 height: typeof innerHeight === "number" ? innerHeight : 0,
30 width: typeof innerWidth === "number" ? innerWidth : 0
31 };
32 } else {
33 // Read the fields explicitly; DOMRect fields are prototype getters,
34 // so spreading a DOMRect (e.g. into state) would copy nothing
35 const { height, width } = getBoundingBox(scrollElement);
36 return { height, width };
37 }
38}
39
40/**
41 * Gets the vertical and horizontal position of an element within its scroll container.

Callers 2

dimensions.test.tsFile · 0.90
measureViewportFunction · 0.90

Calls 2

isWindowFunction · 0.85
getBoundingBoxFunction · 0.85

Tested by

no test coverage detected