Skip to content

Commit

Permalink
Fix error when rendering empty cell in <TableView> (#1308)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown committed Sep 13, 2024
1 parent 98bd2da commit 7e0065e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-cows-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystar/ui': patch
---

Fix error when rendering empty cell in `<TableView>`
37 changes: 14 additions & 23 deletions design-system/pkg/src/table/TableView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export function TableView<T extends object>(

let layout = useMemo(
() =>
new TableViewLayout({
new TableViewLayout<T>({
// If props.overflowMode is wrap, then use estimated heights based on scale, otherwise use fixed heights.
rowHeight:
props.overflowMode === 'wrap' ? undefined : ROW_HEIGHTS[density],
Expand Down Expand Up @@ -406,6 +406,9 @@ export function TableView<T extends object>(
case 'empty': {
return <EmptyState />;
}
default: {
return null;
}
}
}, []);

Expand Down Expand Up @@ -529,11 +532,9 @@ export function TableView<T extends object>(
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}
Expand Down Expand Up @@ -582,7 +583,7 @@ interface TableVirtualizerProps<T> extends HTMLAttributes<HTMLElement> {
layout: TableViewLayout<T>;
collection: TableCollection<T>;
persistedKeys: Set<Key> | null;
renderView: (type: string, content: GridNode<T>) => ReactElement;
renderView: (type: string, content: GridNode<T>) => ReactElement | null;
renderWrapper?: (
parent: View | null,
reusableView: View,
Expand Down Expand Up @@ -1387,13 +1388,15 @@ function TableCell({ cell }: { cell: GridNode<unknown> }) {
ref={ref}
className={cellClassname}
>
<CellContents id={id}>
{isReactText(cell.rendered) ? (
<Text>{cell.rendered}</Text>
) : (
cell.rendered
)}
</CellContents>
{typeof cell.rendered === 'boolean' || cell.rendered == null ? null : (
<CellContents id={id}>
{isReactText(cell.rendered) ? (
<Text>{cell.rendered}</Text>
) : (
cell.rendered
)}
</CellContents>
)}
</div>
</FocusRing>
);
Expand All @@ -1409,18 +1412,6 @@ function CellContents(props: HTMLAttributes<HTMLElement>) {
);
}

export function getWrappedElement(
children: string | ReactElement | ReactNode
): ReactElement {
let element: ReactElement;
if (isReactText(children)) {
element = <span>{children}</span>;
} else {
element = Children.only(children) as ReactElement;
}
return element;
}

function TableCellWrapper(
props: VirtualizerItemOptions & {
parent: View;
Expand Down

0 comments on commit 7e0065e

Please sign in to comment.