react-window 2.3.3 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,7 +33,7 @@ declare type ForbiddenKeys = "ariaAttributes" | "columnIndex" | "rowIndex" | "st
33
33
 
34
34
  declare type ForbiddenKeys_2 = "ariaAttributes" | "index" | "style";
35
35
 
36
- export declare function getScrollbarSize(recalculate?: boolean): number;
36
+ export declare function getScrollbarSize(recalculate?: boolean, ownerDocument?: Document | undefined): number;
37
37
 
38
38
  /**
39
39
  * Renders data with many rows and columns.
@@ -41,27 +41,27 @@ export declare function getScrollbarSize(recalculate?: boolean): number;
41
41
  * ℹ️ Unlike `List` rows, `Grid` cell sizes must be known ahead of time.
42
42
  * Either static sizes or something that can be derived (from the data in `CellProps`) without rendering.
43
43
  */
44
- export declare function Grid<CellProps extends object, TagName extends TagNames = "div">({ cellComponent: CellComponentProp, cellProps: cellPropsUnstable, children, className, columnCount, columnKey, columnWidth, defaultHeight, defaultWidth, dir, gridRef, onCellsRendered, onResize, overscanCount, rowCount, rowHeight, rowKey, style, tagName, ...rest }: GridProps<CellProps, TagName>): ReactElement;
44
+ export declare function Grid<CellProps extends object, TagName extends TagNames = "div">({ cellComponent: CellComponentProp, cellProps: cellPropsUnstable, children, className, columnCount, columnKey, columnWidth, defaultHeight, defaultScrollLeft, defaultScrollTop, defaultWidth, dir, gridRef, onCellsRendered, onResize, overscanCount, rowCount, rowHeight, rowKey, style, tagName, ...rest }: GridProps<CellProps, TagName>): ReactElement;
45
45
 
46
46
  /**
47
47
  * Ref used to interact with this component's imperative API.
48
48
  *
49
49
  * This API has imperative methods for scrolling and a getter for the outermost DOM element.
50
50
  *
51
- * ℹ️ The `useGridRef` and `useGridCallbackRef` hooks are exported for convenience use in TypeScript projects.
51
+ * ℹ️ The `useGridRef` and `useGridCallbackRef` hooks are exported for convenience in TypeScript projects.
52
52
  */
53
53
  export declare interface GridImperativeAPI {
54
54
  /**
55
- * Outermost HTML element for the grid if mounted and null (if not mounted.
55
+ * Outermost HTML element for the grid if mounted and null if not mounted.
56
56
  */
57
57
  get element(): HTMLDivElement | null;
58
58
  /**
59
59
  * Scrolls the grid so that the specified row and column are visible.
60
60
  *
61
61
  * @param behavior Determines whether scrolling is instant or animates smoothly
62
- * @param columnAlign Determines the horizontal alignment of the element within the list
62
+ * @param columnAlign Determines the horizontal alignment of the element within the grid
63
63
  * @param columnIndex Index of the column to scroll to (0-based)
64
- * @param rowAlign Determines the vertical alignment of the element within the list
64
+ * @param rowAlign Determines the vertical alignment of the element within the grid
65
65
  * @param rowIndex Index of the row to scroll to (0-based)
66
66
  *
67
67
  * @throws RangeError if an invalid row or column index is provided
@@ -76,7 +76,7 @@ export declare interface GridImperativeAPI {
76
76
  /**
77
77
  * Scrolls the grid so that the specified column is visible.
78
78
  *
79
- * @param align Determines the horizontal alignment of the element within the list
79
+ * @param align Determines the horizontal alignment of the element within the grid
80
80
  * @param behavior Determines whether scrolling is instant or animates smoothly
81
81
  * @param index Index of the column to scroll to (0-based)
82
82
  *
@@ -90,7 +90,7 @@ export declare interface GridImperativeAPI {
90
90
  /**
91
91
  * Scrolls the grid so that the specified row is visible.
92
92
  *
93
- * @param align Determines the vertical alignment of the element within the list
93
+ * @param align Determines the vertical alignment of the element within the grid
94
94
  * @param behavior Determines whether scrolling is instant or animates smoothly
95
95
  * @param index Index of the row to scroll to (0-based)
96
96
  *
@@ -107,7 +107,7 @@ export declare type GridProps<CellProps extends object, TagName extends TagNames
107
107
  /**
108
108
  * React component responsible for rendering a cell.
109
109
  *
110
- * This component will receive an `index` and `style` prop by default.
110
+ * This component will receive `columnIndex`, `rowIndex`, and `style` props by default.
111
111
  * Additionally it will receive prop values passed to `cellProps`.
112
112
  *
113
113
  * ℹ️ The prop types for this component are exported as `CellComponentProps`
@@ -162,41 +162,74 @@ export declare type GridProps<CellProps extends object, TagName extends TagNames
162
162
  * - number of pixels (number)
163
163
  * - percentage of the grid's current width (string)
164
164
  * - function that returns the column width (in pixels) given an index and `cellProps`
165
+ *
166
+ * ℹ️ Percentage widths can't be resolved during server rendering unless a `defaultWidth` (or a pixel width via the `style` prop) is specified.
165
167
  */
166
168
  columnWidth: number | string | ((index: number, cellProps: CellProps) => number);
167
169
  /**
168
- * Default height of grid for initial render.
169
- * This value is important for server rendering.
170
+ * Default height of grid (in pixels) for initial render, before its actual height has been measured.
171
+ *
172
+ * ℹ️ Grids can't be measured during server rendering, so this value determines how many rows are server rendered.
173
+ * It's recommended to set this to the expected height of the grid (or to specify a pixel height via the `style` prop).
170
174
  */
171
175
  defaultHeight?: number;
172
176
  /**
173
- * Default width of grid for initial render.
174
- * This value is important for server rendering.
177
+ * Initial horizontal scroll offset (in pixels) of the grid.
178
+ * This value is only applied once, when the grid first mounts with at least one column.
179
+ *
180
+ * ℹ️ Server-rendered HTML can't be pre-scrolled, so server rendering always starts at the first column;
181
+ * the default scroll offset is applied once the grid hydrates.
182
+ *
183
+ * ⚠️ If the grid can't be scrolled that far when the offset is applied (e.g. it is hidden with `display: none`,
184
+ * or uses percentage column widths before its width has been measured), the offset is clamped or ignored and not retried.
185
+ * Specify a `defaultWidth` (or a pixel width via the `style` prop) when using percentage column widths.
186
+ */
187
+ defaultScrollLeft?: number;
188
+ /**
189
+ * Initial vertical scroll offset (in pixels) of the grid.
190
+ * This value is only applied once, when the grid first mounts with at least one row.
191
+ *
192
+ * ℹ️ Server-rendered HTML can't be pre-scrolled, so server rendering always starts at the first row;
193
+ * the default scroll offset is applied once the grid hydrates.
194
+ *
195
+ * ⚠️ If the grid can't be scrolled that far when the offset is applied (e.g. it is hidden with `display: none`,
196
+ * or uses percentage row heights before its height has been measured), the offset is clamped or ignored and not retried.
197
+ * Specify a `defaultHeight` (or a pixel height via the `style` prop) when using percentage row heights.
198
+ */
199
+ defaultScrollTop?: number;
200
+ /**
201
+ * Default width of grid (in pixels) for initial render, before its actual width has been measured.
202
+ *
203
+ * ℹ️ Grids can't be measured during server rendering, so this value determines how many columns are server rendered.
204
+ * It's recommended to set this to the expected width of the grid (or to specify a pixel width via the `style` prop).
175
205
  */
176
206
  defaultWidth?: number;
177
207
  /**
178
208
  * Indicates the directionality of grid cells.
179
209
  *
210
+ * ℹ️ The directionality of an ancestor element can't be detected during server rendering;
211
+ * specify this prop explicitly for server-rendered right-to-left grids.
212
+ *
180
213
  * ℹ️ See HTML `dir` [global attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/dir) for more information.
181
214
  */
182
215
  dir?: "ltr" | "rtl";
183
216
  /**
184
217
  * Imperative Grid API.
185
218
  *
186
- * ℹ️ The `useGridRef` and `useGridCallbackRef` hooks are exported for convenience use in TypeScript projects.
219
+ * ℹ️ The `useGridRef` and `useGridCallbackRef` hooks are exported for convenience in TypeScript projects.
187
220
  */
188
221
  gridRef?: Ref<{
189
222
  /**
190
- * Outermost HTML element for the grid if mounted and null (if not mounted.
223
+ * Outermost HTML element for the grid if mounted and null if not mounted.
191
224
  */
192
225
  get element(): HTMLDivElement | null;
193
226
  /**
194
227
  * Scrolls the grid so that the specified row and column are visible.
195
228
  *
196
229
  * @param behavior Determines whether scrolling is instant or animates smoothly
197
- * @param columnAlign Determines the horizontal alignment of the element within the list
230
+ * @param columnAlign Determines the horizontal alignment of the element within the grid
198
231
  * @param columnIndex Index of the column to scroll to (0-based)
199
- * @param rowAlign Determines the vertical alignment of the element within the list
232
+ * @param rowAlign Determines the vertical alignment of the element within the grid
200
233
  * @param rowIndex Index of the row to scroll to (0-based)
201
234
  *
202
235
  * @throws RangeError if an invalid row or column index is provided
@@ -211,7 +244,7 @@ export declare type GridProps<CellProps extends object, TagName extends TagNames
211
244
  /**
212
245
  * Scrolls the grid so that the specified column is visible.
213
246
  *
214
- * @param align Determines the horizontal alignment of the element within the list
247
+ * @param align Determines the horizontal alignment of the element within the grid
215
248
  * @param behavior Determines whether scrolling is instant or animates smoothly
216
249
  * @param index Index of the column to scroll to (0-based)
217
250
  *
@@ -225,7 +258,7 @@ export declare type GridProps<CellProps extends object, TagName extends TagNames
225
258
  /**
226
259
  * Scrolls the grid so that the specified row is visible.
227
260
  *
228
- * @param align Determines the vertical alignment of the element within the list
261
+ * @param align Determines the vertical alignment of the element within the grid
229
262
  * @param behavior Determines whether scrolling is instant or animates smoothly
230
263
  * @param index Index of the row to scroll to (0-based)
231
264
  *
@@ -276,6 +309,8 @@ export declare type GridProps<CellProps extends object, TagName extends TagNames
276
309
  * - number of pixels (number)
277
310
  * - percentage of the grid's current height (string)
278
311
  * - function that returns the row height (in pixels) given an index and `cellProps`
312
+ *
313
+ * ℹ️ Percentage heights can't be resolved during server rendering unless a `defaultHeight` (or a pixel height via the `style` prop) is specified.
279
314
  */
280
315
  rowHeight: number | string | ((index: number, cellProps: CellProps) => number);
281
316
  /**
@@ -299,8 +334,8 @@ export declare type GridProps<CellProps extends object, TagName extends TagNames
299
334
  */
300
335
  style?: CSSProperties;
301
336
  /**
302
- * Can be used to override the root HTML element rendered by the List component.
303
- * The default value is "div", meaning that List renders an HTMLDivElement as its root.
337
+ * Can be used to override the root HTML element rendered by the Grid component.
338
+ * The default value is "div", meaning that Grid renders an HTMLDivElement as its root.
304
339
  *
305
340
  * ⚠️ In most use cases the default ARIA roles are sufficient and this prop is not needed.
306
341
  */
@@ -310,16 +345,16 @@ export declare type GridProps<CellProps extends object, TagName extends TagNames
310
345
  /**
311
346
  * Renders data with many rows.
312
347
  */
313
- export declare function List<RowProps extends object, TagName extends TagNames = "div">({ children, className, defaultHeight, listRef, onResize, onRowsRendered, overscanCount, rowComponent: RowComponentProp, rowCount, rowHeight: rowHeightProp, rowKey, rowProps: rowPropsUnstable, tagName, style, ...rest }: ListProps<RowProps, TagName>): ReactElement;
348
+ export declare function List<RowProps extends object, TagName extends TagNames = "div">({ children, className, defaultHeight, defaultScrollOffset, listRef, onResize, onRowsRendered, overscanCount, rowComponent: RowComponentProp, rowCount, rowHeight: rowHeightProp, rowKey, rowProps: rowPropsUnstable, tagName, style, ...rest }: ListProps<RowProps, TagName>): ReactElement;
314
349
 
315
350
  /**
316
351
  * Imperative List API.
317
352
  *
318
- * ℹ️ The `useListRef` and `useListCallbackRef` hooks are exported for convenience use in TypeScript projects.
353
+ * ℹ️ The `useListRef` and `useListCallbackRef` hooks are exported for convenience in TypeScript projects.
319
354
  */
320
355
  export declare interface ListImperativeAPI {
321
356
  /**
322
- * Outermost HTML element for the list if mounted and null (if not mounted.
357
+ * Outermost HTML element for the list if mounted and null if not mounted.
323
358
  */
324
359
  get element(): HTMLDivElement | null;
325
360
  /**
@@ -346,7 +381,7 @@ export declare interface ListImperativeAPI {
346
381
 
347
382
  export declare type ListProps<RowProps extends object, TagName extends TagNames = "div"> = Omit<HTMLAttributes<HTMLDivElement>, "onResize"> & {
348
383
  /**
349
- * Additional content to be rendered within the list (above cells).
384
+ * Additional content to be rendered within the list (above rows).
350
385
  * This property can be used to render things like overlays or tooltips.
351
386
  */
352
387
  children?: ReactNode;
@@ -355,20 +390,34 @@ export declare type ListProps<RowProps extends object, TagName extends TagNames
355
390
  */
356
391
  className?: string;
357
392
  /**
358
- * Default height of list for initial render.
359
- * This value is important for server rendering.
393
+ * Default height of list (in pixels) for initial render, before its actual height has been measured.
394
+ *
395
+ * ℹ️ Lists can't be measured during server rendering, so this value determines how many rows are server rendered.
396
+ * It's recommended to set this to the expected height of the list (or to specify a pixel height via the `style` prop).
360
397
  */
361
398
  defaultHeight?: number;
399
+ /**
400
+ * Initial scroll offset (in pixels) of the list.
401
+ * This value is only applied once, when the list first mounts with at least one row.
402
+ *
403
+ * ℹ️ Server-rendered HTML can't be pre-scrolled, so server rendering always starts at the first row;
404
+ * the default scroll offset is applied once the list hydrates.
405
+ *
406
+ * ⚠️ If the list can't be scrolled that far when the offset is applied (e.g. it is hidden with `display: none`,
407
+ * or uses percentage row heights before its height has been measured), the offset is clamped or ignored and not retried.
408
+ * Specify a `defaultHeight` (or a pixel height via the `style` prop) when using percentage row heights.
409
+ */
410
+ defaultScrollOffset?: number;
362
411
  /**
363
412
  * Ref used to interact with this component's imperative API.
364
413
  *
365
414
  * This API has imperative methods for scrolling and a getter for the outermost DOM element.
366
415
  *
367
- * ℹ️ The `useListRef` and `useListCallbackRef` hooks are exported for convenience use in TypeScript projects.
416
+ * ℹ️ The `useListRef` and `useListCallbackRef` hooks are exported for convenience in TypeScript projects.
368
417
  */
369
418
  listRef?: Ref<{
370
419
  /**
371
- * Outermost HTML element for the list if mounted and null (if not mounted.
420
+ * Outermost HTML element for the list if mounted and null if not mounted.
372
421
  */
373
422
  get element(): HTMLDivElement | null;
374
423
  /**
@@ -442,10 +491,12 @@ export declare type ListProps<RowProps extends object, TagName extends TagNames
442
491
  /**
443
492
  * Row height; the following formats are supported:
444
493
  * - number of pixels (number)
445
- * - percentage of the grid's current height (string)
446
- * - function that returns the row height (in pixels) given an index and `cellProps`
494
+ * - percentage of the list's current height (string)
495
+ * - function that returns the row height (in pixels) given an index and `rowProps`
447
496
  * - dynamic row height cache returned by the `useDynamicRowHeight` hook
448
497
  *
498
+ * ℹ️ Percentage heights can't be resolved during server rendering unless a `defaultHeight` (or a pixel height via the `style` prop) is specified.
499
+ *
449
500
  * ⚠️ Dynamic row heights are not as efficient as predetermined sizes.
450
501
  * It's recommended to provide your own height values if they can be determined ahead of time.
451
502
  */
@@ -489,8 +540,25 @@ export declare type RowComponentProps<RowProps extends object = object> = Compon
489
540
 
490
541
  declare type TagNames = keyof JSX.IntrinsicElements;
491
542
 
492
- export declare function useDynamicRowHeight({ defaultRowHeight, key }: {
543
+ export declare function useDynamicRowHeight({ defaultRowHeight, initialRowHeights, key }: {
544
+ /**
545
+ * Estimated height (in pixels) of rows that have not yet been measured.
546
+ */
493
547
  defaultRowHeight: number;
548
+ /**
549
+ * Row heights (in pixels) that are known or can be estimated ahead of time, e.g. estimated from each row's content.
550
+ * This can be either an array (where each item is the height of the row at that index) or a Map of row index to height.
551
+ *
552
+ * These values are used in place of `defaultRowHeight` until rows are rendered and measured,
553
+ * so providing them can make server-rendered lists and initial scroll positions more accurate.
554
+ *
555
+ * ℹ️ This value is only read when the hook first mounts and when the `key` changes.
556
+ */
557
+ initialRowHeights?: ReadonlyMap<number, number> | readonly number[];
558
+ /**
559
+ * Changing this value clears all measured row heights,
560
+ * e.g. when the list renders a different set of data.
561
+ */
494
562
  key?: string | number;
495
563
  }): DynamicRowHeight;
496
564