11import {
2+ createElement ,
23 memo ,
34 useEffect ,
45 useImperativeHandle ,
@@ -9,13 +10,17 @@ import {
910import { useIsRtl } from "../../core/useIsRtl" ;
1011import { useVirtualizer } from "../../core/useVirtualizer" ;
1112import { useMemoizedObject } from "../../hooks/useMemoizedObject" ;
12- import type { Align } from "../../types" ;
13+ import type { Align , TagNames } from "../../types" ;
1314import { arePropsEqual } from "../../utils/arePropsEqual" ;
1415import type { GridProps } from "./types" ;
1516
16- export function Grid < CellProps extends object > ( {
17+ export function Grid <
18+ CellProps extends object ,
19+ TagName extends TagNames = "div"
20+ > ( {
1721 cellComponent : CellComponentProp ,
1822 cellProps : cellPropsUnstable ,
23+ children,
1924 className,
2025 columnCount,
2126 columnWidth,
@@ -29,8 +34,9 @@ export function Grid<CellProps extends object>({
2934 rowCount,
3035 rowHeight,
3136 style,
37+ tagName = "div" as TagName ,
3238 ...rest
33- } : GridProps < CellProps > ) {
39+ } : GridProps < CellProps , TagName > ) {
3440 const cellProps = useMemoizedObject ( cellPropsUnstable ) ;
3541 const CellComponent = useMemo (
3642 ( ) => memo ( CellComponentProp , arePropsEqual ) ,
@@ -247,16 +253,28 @@ export function Grid<CellProps extends object>({
247253 rowStopIndex
248254 ] ) ;
249255
250- return (
256+ const sizingElement = (
251257 < div
252- aria-colcount = { columnCount }
253- aria-rowcount = { rowCount }
254- role = "grid"
255- { ...rest }
256- className = { className }
257- dir = { dir }
258- ref = { setElement }
258+ aria-hidden
259259 style = { {
260+ height : getEstimatedHeight ( ) ,
261+ width : getEstimatedWidth ( ) ,
262+ zIndex : - 1
263+ } }
264+ > </ div >
265+ ) ;
266+
267+ return createElement (
268+ tagName ,
269+ {
270+ "aria-colcount" : columnCount ,
271+ "aria-rowcount" : rowCount ,
272+ role : "grid" ,
273+ ...rest ,
274+ className,
275+ dir,
276+ ref : setElement ,
277+ style : {
260278 position : "relative" ,
261279 width : "100%" ,
262280 height : "100%" ,
@@ -265,18 +283,10 @@ export function Grid<CellProps extends object>({
265283 flexGrow : 1 ,
266284 overflow : "auto" ,
267285 ...style
268- } }
269- >
270- { cells }
271-
272- < div
273- aria-hidden
274- style = { {
275- height : getEstimatedHeight ( ) ,
276- width : getEstimatedWidth ( ) ,
277- zIndex : - 1
278- } }
279- > </ div >
280- </ div >
286+ }
287+ } ,
288+ cells ,
289+ children ,
290+ sizingElement
281291 ) ;
282292}
0 commit comments