SpreadsheetGrid
API reference

preloadGridPopups and /testing

Preloading popover parts, and testing helpers for drawing the grid in jsdom

One reference for both the React and Solid versions

Props, column definitions, handle methods, callbacks, and CSS classes and tokens are the same in both. The example code is written for React. Pick Solid at the top of the sidebar to see how to read it for the Solid version here.

Lazy loading of popover parts (preloadGridPopups)

The parts of the column filter popover and the tool panel (filter manager / column visibility / sorting) are split into a chunk separate from the core and aren't in the initial load (the initial JS is about 10% smaller; props / handle are the same).

  • After mounting, when the browser is idle (requestIdleCallback; about 200ms later in environments without it), the grid preloads the parts only when that feature can be used (column filters = enableColumnFilter and there are columns with filterType / tool panel = any of filters, the column menu or sorting can be used).
  • When opened before the preload, it loads on the spot, and the parts don't appear until loading finishes (focus goes into the input once they appear. Escape closes it even while loading). The grid doesn't re-render just because a preload finished.
  • When loading fails, it logs to console.error and closes (it tries to load again the next time it opens, but some browsers remember a failed dynamic import until the page reloads).
  • Assumes a bundler that supports dynamic import (import()) (Vite / webpack / Next.js / Rollup / esbuild and so on). The CJS build loads with require.
import { preloadGridPopups } from '@ishibashi0112/spreadsheet-grid';
FunctionDescription
preloadGridPopups(): Promise<void>Loads the parts ahead of time. Usually not needed (the grid preloads automatically). Use it when a test checks the contents synchronously right after opening a popover (await it in beforeAll), or when you want them loaded before a page transition.

Testing helpers (the /testing subpath)

jsdom doesn't compute layout, so with plain jsdom not a single row or column of a real grid is drawn (vertical: the scroll element's clientHeight / clientWidth are 0. Horizontal: column virtualization (@tanstack/virtual-core) gets its rectangle from ResizeObserver notifications, so with a no-op stub the width stays 0). installJsdomLayoutStubs() from @ishibashi0112/spreadsheet-grid/testing solves all of this at once.

// @vitest-environment jsdom
import { installJsdomLayoutStubs } from '@ishibashi0112/spreadsheet-grid/testing';

beforeAll(() => {
  installJsdomLayoutStubs(); // default 1200×600. Change with { width, height }
});
  • What it installs: HTMLElement.prototype.clientHeight / clientWidth (fixed getters), Element.prototype.getBoundingClientRect (a fixed rectangle), globalThis.ResizeObserver (a stub that calls back immediately on observe), Element.prototype.scrollTo (a no-op if missing).
  • The return value is a restore function that goes back to before installing (for afterAll(restore); optional).
  • A small module independent of React, separate from the main bundle (dist/testing.js).
  • When the stubs are installed twice, restore them in the reverse order of installing (restoring in the same order leaves the first stub's values).
  • With this you can verify the drawing of .ssg-body-row / .ssg-body-cell, the classes added and cell text in the DOM (the library's own SpreadsheetGrid.jsdomLayoutStubs.integration.test.tsx guarantees it works). Virtualization still applies, so only the rows and columns that fit in the stub's size (plus overscan) are drawn (with the default 1200×600, a row height of 36px and 120px-wide columns, about 38 rows and about 18 columns; the grid's height doesn't change it). To draw everything, make the stub bigger ({ width: 3000, height: 4000 } and so on), or write scrollTop / scrollLeft of .ssg-scroll-container and fire fireEvent.scroll. The handle's scrollToRow / scrollToCell do nothing in jsdom (the stub's scrollTo is a no-op). Rows are also drawn in pinned panes, and the row number "#" is in the rows of the left pane (since 0.63.0, even in tables without left-pinned columns), so to count rows / get cells of the n-th row, use the rows of the center pane ([data-pane="center"].ssg-body-row).
  • Tests that check the contents synchronously right after opening the column filter popover / tool panel find nothing there until lazy loading of the parts has finished. Load them first with beforeAll(() => preloadGridPopups()) (imported from the main entry; from /lite for /lite grids), or wait with findBy* / waitFor (Lazy loading of popover parts).
  • Common operations: pasting reads the paste event's clipboardData, so use user-event's user.paste('a\tb') or fireEvent.paste(shell, { clipboardData: { getData: () => 'a\tb' } }) (the Ctrl+V key alone doesn't paste). Copying writes with navigator.clipboard.writeText (after userEvent.setup() it can be read with navigator.clipboard.readText()). jsdom has no coordinates, so select ranges with Shift+arrows / Shift+click / selectRange. Moving the active cell after commit / cancel and accepting the next edit happen in a later microtask, so when continuing synchronously with fireEvent, put await act(async () => {}) in between. The date editor is a native <input type="date">, so use fireEvent.change. selectCell / setActiveCell don't move focus, so call focus() before sending keys. Focus moves into the column filter popover's input 2 frames after it opens (after its position is decided), so wait with await waitFor(() => expect(input).toHaveFocus()) (on close it returns to the grid right away; 1.0.2).
  • Tests that start typing a number column with digits: in jsdom / happy-dom + user-event, user.keyboard('42') becomes "24" (jsdom doesn't keep the caret position of the <input type="number"> opened by the first character, so the second character goes in at the start; "42" in real browsers). Open it with the first character and continue into the input with await user.type(input, '2'), or open with Enter / F2 and write await user.clear(input) + await user.type(input, '42').
  • Jest: there is a CommonJS entry, so it loads as is. Map CSS imports with moduleNameMapper: { '\\.css$': 'identity-obj-proxy' } or similar. Jest 30's jsdom (26) has no PointerEvent, and fireEvent alone doesn't select cells, so write cell presses with user-event, or with the handle's selectCell + focus().

On this page