Skip to content
Draft
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
7 changes: 7 additions & 0 deletions .changeset/heavy-donuts-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@clickhouse/click-ui": patch
---

`Table` accepts a new `tableLayout` prop controlling its layout. Possible values: `'auto'`, `'fixed'`. Changes the default from
`table-layout: fixed` to `table-layout: auto`, making tables adjust to their contents better. When overflown, tables gain horizontal scroll
instead of squishing their contents.
7 changes: 7 additions & 0 deletions src/components/Table/Table.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
width: 100%;
overflow: visible;
border-collapse: collapse;
}

.table__table_layout_auto {
table-layout: auto;
}

.table__table_layout_fixed {
table-layout: fixed;
}

Expand Down
16 changes: 15 additions & 1 deletion src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,18 @@ const Thead = ({
);
};

const tableVariants = cva(styles.table__table, {
variants: {
layout: {
auto: styles.table__table_layout_auto,
fixed: styles.table__table_layout_fixed,
},
},
defaultVariants: {
layout: 'auto',
},
});

const rowVariants = cva(styles.table__row, {
variants: {
isSelectable: {
Expand Down Expand Up @@ -380,6 +392,7 @@ interface CommonTableProps extends Omit<
rowHeight?: string;
resizableColumns?: boolean;
mobileLayout?: MobileLayoutProp;
tableLayout?: 'auto' | 'fixed';
}

type SelectReturnValue = {
Expand Down Expand Up @@ -586,6 +599,7 @@ const Table = forwardRef<HTMLTableElement, TableProps>(
resizableColumns,
mobileLayout = 'list',
className,
tableLayout = 'auto',
...props
},
ref
Expand Down Expand Up @@ -848,7 +862,7 @@ const Table = forwardRef<HTMLTableElement, TableProps>(
<table
ref={ref}
{...props}
className={cn(styles['table__table'], className)}
className={tableVariants({ layout: tableLayout, className })}
>
{showHeader && (
<Thead
Expand Down
Loading