From 7e0065e042d44171d8a7386ec069c3d785b75521 Mon Sep 17 00:00:00 2001 From: Emma Hamilton Date: Fri, 13 Sep 2024 10:49:40 +1000 Subject: [PATCH] Fix error when rendering empty cell in `` (#1308) --- .changeset/late-cows-tie.md | 5 +++ design-system/pkg/src/table/TableView.tsx | 37 +++++++++-------------- 2 files changed, 19 insertions(+), 23 deletions(-) create mode 100644 .changeset/late-cows-tie.md diff --git a/.changeset/late-cows-tie.md b/.changeset/late-cows-tie.md new file mode 100644 index 000000000..4acfbac5b --- /dev/null +++ b/.changeset/late-cows-tie.md @@ -0,0 +1,5 @@ +--- +'@keystar/ui': patch +--- + +Fix error when rendering empty cell in `` diff --git a/design-system/pkg/src/table/TableView.tsx b/design-system/pkg/src/table/TableView.tsx index 8bd8e71b6..1db9fba49 100644 --- a/design-system/pkg/src/table/TableView.tsx +++ b/design-system/pkg/src/table/TableView.tsx @@ -196,7 +196,7 @@ export function TableView( let layout = useMemo( () => - new TableViewLayout({ + new TableViewLayout({ // If props.overflowMode is wrap, then use estimated heights based on scale, otherwise use fixed heights. rowHeight: props.overflowMode === 'wrap' ? undefined : ROW_HEIGHTS[density], @@ -406,6 +406,9 @@ export function TableView( case 'empty': { return ; } + default: { + return null; + } } }, []); @@ -529,11 +532,9 @@ export function TableView( className={classNames(tableClassname, styleProps.className)} tableState={state} cosmeticConfig={cosmeticConfig} - // @ts-expect-error layout={layout} collection={state.collection} persistedKeys={persistedKeys} - // @ts-expect-error renderView={renderView} // @ts-expect-error renderWrapper={renderWrapper} @@ -582,7 +583,7 @@ interface TableVirtualizerProps extends HTMLAttributes { layout: TableViewLayout; collection: TableCollection; persistedKeys: Set | null; - renderView: (type: string, content: GridNode) => ReactElement; + renderView: (type: string, content: GridNode) => ReactElement | null; renderWrapper?: ( parent: View | null, reusableView: View, @@ -1387,13 +1388,15 @@ function TableCell({ cell }: { cell: GridNode }) { ref={ref} className={cellClassname} > - - {isReactText(cell.rendered) ? ( - {cell.rendered} - ) : ( - cell.rendered - )} - + {typeof cell.rendered === 'boolean' || cell.rendered == null ? null : ( + + {isReactText(cell.rendered) ? ( + {cell.rendered} + ) : ( + cell.rendered + )} + + )} ); @@ -1409,18 +1412,6 @@ function CellContents(props: HTMLAttributes) { ); } -export function getWrappedElement( - children: string | ReactElement | ReactNode -): ReactElement { - let element: ReactElement; - if (isReactText(children)) { - element = {children}; - } else { - element = Children.only(children) as ReactElement; - } - return element; -} - function TableCellWrapper( props: VirtualizerItemOptions & { parent: View;