Skip to content
TypeScript

fix(web): keep expanded tool actions usable from the keyboard (#18831)

Alex Southwell5a264a8b3435
diff --git a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
index a4451656d66..8b251da3be2 100644
--- a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
+++ b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
@@ -194,6 +194,42 @@ async function click(element: HTMLElement) {
}
describe("MessagesTimeline work rows", () => {
+ it.each([
+ ["Enter", "{Enter}"],
+ ["Space", " "],
+ ])("opens a nested diff with %s without collapsing the tool row", async (_name, key) => {
+ const onOpenTurnDiff = vi.fn();
+ await renderTimeline(
+ [
+ work("file-change-1", {
+ label: "Updated src/index.ts",
+ tone: "tool",
+ itemType: "file_change",
+ toolLifecycleStatus: "completed",
+ projectedItem: v2Item("file_change", { id: "file-change-1", fileName: "src/index.ts" }),
+ }),
+ ],
+ { onOpenTurnDiff },
+ );
+ const row = container.querySelector<HTMLElement>('[data-v2-item-type="file_change"]')!;
+ const press = async (target: HTMLElement) => {
+ await act(async () => {
+ target.focus();
+ await userEvent.keyboard(key);
+ });
+ };
+ expect(row.getAttribute("aria-expanded")).toBe("false");
+ await press(row);
+ expect(row.getAttribute("aria-expanded")).toBe("true");
+ const openDiff = button("Open diff");
+ await press(openDiff);
+ expect(onOpenTurnDiff).toHaveBeenCalledWith("run-1", "src/index.ts");
+ expect(onOpenTurnDiff).toHaveBeenCalledTimes(1);
+ expect(row.getAttribute("aria-expanded")).toBe("true");
+ await press(row);
+ expect(row.getAttribute("aria-expanded")).toBe("false");
+ });
+
it("shows dynamic tool input without cached output when the row is expanded", async () => {
await renderTimeline([
work("tool-with-cached-output", {
diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsx
index e8551c8de65..aed65120ea0 100644
--- a/apps/web/src/components/chat/MessagesTimeline.tsx
+++ b/apps/web/src/components/chat/MessagesTimeline.tsx
@@ -5439,7 +5439,7 @@ function WorkEntryLogRow(props: WorkEntryRowProps) {
"aria-expanded": expanded,
onClick: toggleExpanded,
onKeyDown: (e: KeyboardEvent<HTMLDivElement>) => {
- if (e.key === "Enter" || e.key === " ") {
+ if (e.target === e.currentTarget && (e.key === "Enter" || e.key === " ")) {
e.preventDefault();
toggleExpanded();
}