@@ -36,7 +36,10 @@ import { Checkbox } from "@tiller-ds/form-elements";
36
36
import { ComponentTokens , cx , TokenProps , useIcon , useTokens } from "@tiller-ds/theme" ;
37
37
import { createNamedContext , findChild } from "@tiller-ds/util" ;
38
38
39
- type DataTableChild < T extends object > = React . ReactElement < DataTableColumnProps < T > | DataTableExpanderProps < T > > ;
39
+ type DataTableChild < T extends object > =
40
+ | React . ReactElement < DataTableColumnProps < T > | DataTableExpanderProps < T > >
41
+ | React . ReactElement < DataTableColumnProps < T > | DataTableExpanderProps < T > > [ ]
42
+ | undefined ;
40
43
41
44
export type DataTableProps < T extends object > = {
42
45
/**
@@ -490,13 +493,37 @@ function DataTable<T extends object>({
490
493
const primaryRow = findChild ( "DataTablePrimaryRow" , children ) ;
491
494
const secondaryRow = findChild ( "DataTableSecondaryRow" , children ) ;
492
495
const hasSecondaryColumns = React . isValidElement ( secondaryRow ) ;
493
- const primaryColumnChildren = React . isValidElement ( primaryRow ) ? primaryRow . props . children : children ;
496
+
497
+ const primaryColumnChildren = React . useMemo ( ( ) => {
498
+ return mapChildren ( React . isValidElement ( primaryRow ) ? primaryRow . props . children : children ) ;
499
+ } , [ primaryRow , children ] ) ;
500
+
494
501
const primaryColumnChildrenArray = React . Children . toArray ( primaryColumnChildren ) . filter ( Boolean ) ;
495
502
const columnChildrenSize = primaryColumnChildrenArray . length ;
496
503
497
- const secondaryColumnChildren = React . isValidElement ( secondaryRow ) ? secondaryRow . props . children : null ;
504
+ const secondaryColumnChildren = React . useMemo ( ( ) => {
505
+ return React . isValidElement ( secondaryRow ) ? mapChildren ( secondaryRow . props . children ) : null ;
506
+ } , [ secondaryRow , children ] ) ;
507
+
498
508
const secondaryColumnChildrenArray = React . Children . toArray ( secondaryColumnChildren ) . filter ( Boolean ) ;
499
509
510
+ function mapChildren ( children : DataTableChild < T > [ ] ) {
511
+ return children . map ( ( child ) => {
512
+ if ( ! child ) {
513
+ return undefined ;
514
+ }
515
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
516
+ // @ts -ignore
517
+ if ( Array . isArray ( child . props ?. children ) ) {
518
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
519
+ // @ts -ignore
520
+ return mapChildren ( child . props ?. children ) ;
521
+ } else {
522
+ return child ;
523
+ }
524
+ } ) ;
525
+ }
526
+
500
527
const totalColumnChildrenSize = hasSecondaryColumns
501
528
? secondaryColumnChildrenArray . length + columnChildrenSize
502
529
: columnChildrenSize ;
0 commit comments