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

Function getGridState

integrations/tests/tests/scroll-element.spec.tsx:229–281  ·  view source on GitHub ↗
(page: Page)

Source from the content-addressed store, hash-verified

227});
228
229async function getGridState(page: Page) {
230 return page.evaluate(() => {
231 const grid = document.querySelector<HTMLElement>('[role="grid"]')!;
232 const gridRect = grid.getBoundingClientRect();
233 const viewRight = document.documentElement.clientWidth;
234 const viewBottom = document.documentElement.clientHeight;
235
236 // Region of the grid's client area that is visible within the viewport
237 const left = Math.max(gridRect.left + grid.clientLeft, 0);
238 const right = Math.min(
239 gridRect.left + grid.clientLeft + grid.clientWidth,
240 viewRight
241 );
242 const top = Math.max(gridRect.top + grid.clientTop, 0);
243 const bottom = Math.min(
244 gridRect.top + grid.clientTop + grid.clientHeight,
245 viewBottom
246 );
247
248 const cells = Array.from(grid.querySelectorAll<HTMLElement>("[data-row]"));
249 const rects = cells.map((cell) => cell.getBoundingClientRect());
250
251 // Sample points within the visible region; each must be covered by a rendered cell
252 let uncovered = 0;
253 if (right > left && bottom > top) {
254 for (let x = left + 1; x < right; x += 37) {
255 for (let y = top + 1; y < bottom; y += 13) {
256 if (
257 !rects.some(
258 (rect) =>
259 x >= rect.left &&
260 x <= rect.right &&
261 y >= rect.top &&
262 y <= rect.bottom
263 )
264 ) {
265 uncovered++;
266 }
267 }
268 }
269 }
270
271 return {
272 gridScrollsHorizontally: grid.scrollWidth > grid.clientWidth,
273 gridScrollsVertically: grid.scrollHeight > grid.clientHeight,
274 pageScrollsHorizontally:
275 document.documentElement.scrollWidth >
276 document.documentElement.clientWidth,
277 renderedCells: cells.length,
278 uncovered
279 };
280 });
281}
282
283test.describe("Grid with window scrollElement", () => {
284 test("rows scroll with the page and columns scroll within the grid", async ({

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected