Skip to content

Commit 9e06928

Browse files
maria-rcksclaude
andcommitted
fix(web): collapse a tool call by clicking its expanded label
Expanded tool-call labels re-enable text selection and stopped every click from reaching the row's toggle, so a standalone completed call could be expanded by its label but never collapsed the same way. The label now only withholds the click when it ends a real text selection. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent b7b3ef1 commit 9e06928

2 files changed

Lines changed: 78 additions & 1 deletion

File tree

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,4 +1764,69 @@ describe("MessagesTimeline", () => {
17641764
expect(markup).toContain("lucide-circle-alert");
17651765
expect(markup).toContain("text-destructive");
17661766
});
1767+
1768+
it("collapses a standalone tool call from its expanded label unless text is selected", async () => {
1769+
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
1770+
vi.stubGlobal("requestAnimationFrame", () => 0);
1771+
vi.stubGlobal("cancelAnimationFrame", () => {});
1772+
let renderer: ReactTestRenderer | undefined;
1773+
try {
1774+
await act(() => {
1775+
renderer = create(
1776+
<MessagesTimeline
1777+
{...buildProps()}
1778+
timelineEntries={[
1779+
{
1780+
id: "entry-standalone",
1781+
kind: "work",
1782+
createdAt: MESSAGE_CREATED_AT,
1783+
entry: {
1784+
id: "work-standalone",
1785+
createdAt: MESSAGE_CREATED_AT,
1786+
toolCallId: "call-standalone",
1787+
label: "Run lint",
1788+
tone: "tool",
1789+
itemType: "command_execution",
1790+
command: "pnpm lint",
1791+
toolLifecycleStatus: "completed",
1792+
},
1793+
},
1794+
]}
1795+
/>,
1796+
);
1797+
});
1798+
const row = () => renderer!.root.findByProps({ "aria-label": "pnpm lint" });
1799+
// The label is nested inside the row, so a browser click runs the label
1800+
// handler first and then reaches the row unless the label stops it.
1801+
const clickLabel = async (isCollapsed: boolean) => {
1802+
const label = row().findAll(
1803+
(node) =>
1804+
node.type === "span" &&
1805+
typeof node.props.className === "string" &&
1806+
node.props.className.includes("select-text"),
1807+
)[0];
1808+
let reachedRow = true;
1809+
await act(() =>
1810+
label!.props.onClick({
1811+
currentTarget: { ownerDocument: { getSelection: () => ({ isCollapsed }) } },
1812+
stopPropagation: () => {
1813+
reachedRow = false;
1814+
},
1815+
}),
1816+
);
1817+
if (reachedRow) await act(() => row().props.onClick());
1818+
};
1819+
1820+
await act(() => row().props.onClick());
1821+
expect(row().props["aria-expanded"]).toBe(true);
1822+
1823+
await clickLabel(false);
1824+
expect(row().props["aria-expanded"]).toBe(true);
1825+
1826+
await clickLabel(true);
1827+
expect(row().props["aria-expanded"]).toBe(false);
1828+
} finally {
1829+
await act(() => renderer?.unmount());
1830+
}
1831+
});
17671832
});

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3172,6 +3172,18 @@ function workEntryIconName(workEntry: TimelineWorkEntry): WorkEntryIconName {
31723172

31733173
const stopRowToggle = (e: { stopPropagation: () => void }) => e.stopPropagation();
31743174

3175+
/**
3176+
* Click handler for expanded row labels, which turn text selection back on.
3177+
* Only a click that ends a real selection is withheld from the row toggle, so
3178+
* an ordinary click on the label still bubbles and collapses the row it opened.
3179+
*/
3180+
const stopRowToggleWhileSelectingText = (e: MouseEvent<HTMLElement>) => {
3181+
const selection = e.currentTarget.ownerDocument.getSelection();
3182+
if (selection && !selection.isCollapsed) {
3183+
e.stopPropagation();
3184+
}
3185+
};
3186+
31753187
/**
31763188
* A1 spawn CTA: one anchored row per workflow run (or per-turn direct-spawn
31773189
* batch). Live status is derived from the shared agent panel model at render
@@ -3407,7 +3419,7 @@ const PlainWorkEntryRow = memo(function PlainWorkEntryRow(props: {
34073419
expanded ? "whitespace-pre-wrap break-words select-text" : "truncate",
34083420
headingClass,
34093421
)}
3410-
onClick={expanded ? stopRowToggle : undefined}
3422+
onClick={expanded ? stopRowToggleWhileSelectingText : undefined}
34113423
onPointerDown={expanded ? stopRowToggle : undefined}
34123424
>
34133425
{previewText}

0 commit comments

Comments
 (0)