Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when rendering empty cell in <TableView> #1308

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading