Skip to content

Commit 2c590ba

Browse files
committed
fix(web): wide chat tables fit the lane when cells wrap
With Word wrap on, table cells wrapped but the table still laid out at its unwrapped width, so the last columns were cut off at the lane edge behind a scrollbar that only shows on hover. In a timeline row at least 36rem wide an expanded table now fits the lane and its columns narrow down to their longest word. Phone-width lanes and collapsed tables keep scrolling sideways. The expand toggle no longer pins header widths, which held columns at their collapsed widths and kept an expanded table from fitting.
1 parent e4fb9f2 commit 2c590ba

3 files changed

Lines changed: 20 additions & 25 deletions

File tree

‎apps/web/src/components/ChatMarkdown.tsx‎

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -532,34 +532,13 @@ function readInitialWordWrapSetting(): boolean {
532532

533533
function MarkdownTable({ children, ...props }: React.ComponentProps<"table">) {
534534
const containerRef = useRef<HTMLDivElement | null>(null);
535-
const tableRef = useRef<HTMLTableElement | null>(null);
536535
const [expanded, setExpanded] = useState(readInitialWordWrapSetting);
537536
const [copied, setCopied] = useState(false);
538537
const copiedTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
539538
const expandLabel = expanded ? "Collapse table cells" : "Expand table cells";
540539
const copyLabel = copied ? "Copied" : "Copy table";
541540

542541
function toggleExpanded() {
543-
const table = tableRef.current;
544-
if (!table) return;
545-
546-
if (!expanded) {
547-
const rows = [...table.rows];
548-
const columnWidths = rows.reduce<number[]>((widths, row) => {
549-
[...row.cells].forEach((cell, columnIndex) => {
550-
widths[columnIndex] = Math.max(
551-
widths[columnIndex] ?? 0,
552-
cell.getBoundingClientRect().width,
553-
);
554-
});
555-
return widths;
556-
}, []);
557-
558-
[...(table.tHead?.rows[0]?.cells ?? [])].forEach((cell, columnIndex) => {
559-
cell.style.minWidth = `${columnWidths[columnIndex] ?? cell.getBoundingClientRect().width}px`;
560-
});
561-
}
562-
563542
setExpanded((value) => !value);
564543
}
565544

@@ -606,9 +585,7 @@ function MarkdownTable({ children, ...props }: React.ComponentProps<"table">) {
606585
data-expanded={expanded ? "true" : "false"}
607586
>
608587
<ScrollArea radius="none" chainVerticalScroll scrollFade className="w-full max-w-full">
609-
<table ref={tableRef} {...props}>
610-
{children}
611-
</table>
588+
<table {...props}>{children}</table>
612589
</ScrollArea>
613590
<div className="mt-0.5 flex items-center justify-between select-none">
614591
<Tooltip>

‎apps/web/src/components/chat/MessagesTimeline.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,10 @@ const ConversationTimeline = memo(function ConversationTimeline({
13811381

13821382
const renderItem = ({ item }: { item: MessagesTimelineRow }) => (
13831383
<div className="messages-timeline-row-frame">
1384-
<div className="chat-content-lane overflow-x-clip" data-timeline-root="true">
1384+
<div
1385+
className="@container/chat-lane chat-content-lane overflow-x-clip"
1386+
data-timeline-root="true"
1387+
>
13851388
<TimelineRowContent row={item} />
13861389
</div>
13871390
</div>

‎apps/web/src/index.css‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,6 +2074,21 @@ code {
20742074
overflow-wrap: anywhere;
20752075
}
20762076

2077+
/* Expanded cells wrap, so in a timeline row wide enough for wrapped columns
2078+
(the chat-lane container in MessagesTimeline) the table fits the lane: each
2079+
column can narrow to its longest word, and only a table whose words still do
2080+
not fit scrolls. Phone-width lanes keep the natural column widths and scroll,
2081+
since fitting there leaves prose columns a word or two wide. */
2082+
@container chat-lane (min-width: 36rem) {
2083+
.chat-markdown .chat-markdown-table-container[data-expanded="true"] table {
2084+
min-width: 0;
2085+
}
2086+
2087+
.chat-markdown .chat-markdown-table-container[data-expanded="true"] td {
2088+
overflow-wrap: break-word;
2089+
}
2090+
}
2091+
20772092
:root {
20782093
--diff-addition: var(--success);
20792094
--diff-deletion: var(--destructive);

0 commit comments

Comments
 (0)