Skip to content

Commit 0293a13

Browse files
committed
fix(ui): keep composer model picker stable while typing
1 parent ff73a14 commit 0293a13

5 files changed

Lines changed: 125 additions & 75 deletions

File tree

‎ui/src/pages/chat/chat-composer.test.ts‎

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,14 @@ describe("renderChatComposer controls", () => {
209209
actionLabel: "Unarchive",
210210
onAction,
211211
},
212+
typingActors: [{ id: "ayaan", label: "Ayaan" }],
212213
});
213214

214215
const banner = container.querySelector(".agent-chat__disabled-banner");
215216
expect(banner?.textContent).toContain("This session is archived.");
216217
expect(container.querySelector(".agent-chat__input")).toBeNull();
217218
expect(container.querySelector("textarea")).toBeNull();
219+
expect(container.querySelector(".agent-chat__typing-indicator--outside")).toBeNull();
218220
banner?.querySelector<HTMLButtonElement>("button")?.click();
219221
expect(onAction).toHaveBeenCalledOnce();
220222
button(container, t("chat.runControls.stopGenerating")).click();
@@ -832,39 +834,6 @@ describe("renderChatComposer controls", () => {
832834
});
833835

834836
describe("renderChatComposer status", () => {
835-
it.each([
836-
{
837-
actors: [{ id: "ayaan", label: "Ayaan" }],
838-
expectedText: "Ayaan is typing…",
839-
expectedAvatars: 1,
840-
},
841-
{
842-
actors: [
843-
{ id: "ayaan", label: "Ayaan" },
844-
{ id: "liam", label: "Liam" },
845-
{ id: "maya", label: "Maya" },
846-
{ id: "zoe", label: "Zoe" },
847-
],
848-
expectedText: "Ayaan, Liam, Maya, Zoe are typing…",
849-
expectedAvatars: 3,
850-
},
851-
])(
852-
"keeps $expectedText in the permanent composer footer",
853-
({ actors, expectedText, expectedAvatars }) => {
854-
const { container } = renderComposer({ typingActors: actors });
855-
856-
const indicator = container.querySelector(".agent-chat__typing-indicator");
857-
expect(indicator?.closest(".agent-chat__composer-footer")).not.toBeNull();
858-
expect(indicator?.closest(".agent-chat__input")?.firstElementChild).not.toBe(indicator);
859-
expect(indicator?.querySelectorAll(".chat-author-avatar")).toHaveLength(expectedAvatars);
860-
// The status text already names every typer; avatars must stay out of the
861-
// accessibility tree or screen readers announce each name twice.
862-
const avatars = indicator?.querySelector(".agent-chat__typing-avatars");
863-
expect(avatars?.getAttribute("aria-hidden")).toBe("true");
864-
expect(indicator?.textContent).toContain(expectedText);
865-
},
866-
);
867-
868837
it("swaps the expanded question with the composer and restores its draft and focus", async () => {
869838
const container = document.createElement("div");
870839
document.body.append(container);
@@ -876,6 +845,7 @@ describe("renderChatComposer status", () => {
876845
gatewayQuestionPrompts: [],
877846
composerControls: html`<button type="button">Model</button>`,
878847
onRequestUpdate: vi.fn(),
848+
typingActors: [{ id: "ayaan", label: "Ayaan" }],
879849
});
880850
composerProps.onDraftChange = (next) => {
881851
composerProps.draft = next;
@@ -900,6 +870,7 @@ describe("renderChatComposer status", () => {
900870
await panel.updateComplete;
901871
expect(container.querySelector(".agent-chat__input")).toBeNull();
902872
expect(container.querySelector(".agent-chat__composer-footer")).toBeNull();
873+
expect(container.querySelector(".agent-chat__typing-indicator--outside")).toBeNull();
903874
expect(document.activeElement).toBe(panel.querySelector(".chat-question-panel"));
904875
expect(composerProps.draft).toBe("Keep this draft while composing");
905876

‎ui/src/pages/chat/chat-responsive.browser.test.ts‎

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ type ChatFixtureOptions = {
137137
sessionRailDocked?: boolean;
138138
singleAgent?: boolean;
139139
slashMenu?: boolean;
140+
typingIndicator?: boolean;
140141
};
141142

142143
function expectFiniteRect(rect: Pick<ControlRect, "x" | "y" | "width" | "height">) {
@@ -424,6 +425,18 @@ function chatHtml(opts: ChatFixtureOptions = {}, mobileNavLayout = false) {
424425
</openclaw-chat-session-rail>`
425426
: ""
426427
}
428+
${
429+
opts.crowdedComposerFooter || opts.typingIndicator
430+
? `<div class="agent-chat__typing-indicator agent-chat__typing-indicator--outside" role="status">
431+
<span class="agent-chat__typing-avatars" aria-hidden="true">
432+
<span class="chat-author-avatar">A</span>
433+
<span class="chat-author-avatar">B</span>
434+
<span class="chat-author-avatar">C</span>
435+
</span>
436+
<span class="agent-chat__typing-text">Alexandria, Bartholomew, and Cassandra are typing</span>
437+
</div>`
438+
: ""
439+
}
427440
<div class="agent-chat__composer-shell">
428441
<div class="agent-chat__input">
429442
${
@@ -482,18 +495,6 @@ function chatHtml(opts: ChatFixtureOptions = {}, mobileNavLayout = false) {
482495
</div>
483496
<div class="agent-chat__composer-footer">
484497
${composerControlsHtml(opts.crowdedComposerFooter)}
485-
${
486-
opts.crowdedComposerFooter
487-
? `<div class="agent-chat__typing-indicator" role="status">
488-
<span class="agent-chat__typing-avatars" aria-hidden="true">
489-
<span class="chat-author-avatar">A</span>
490-
<span class="chat-author-avatar">B</span>
491-
<span class="chat-author-avatar">C</span>
492-
</span>
493-
<span class="agent-chat__typing-text">Alexandria, Bartholomew, and Cassandra are typing</span>
494-
</div>`
495-
: ""
496-
}
497498
<div class="agent-chat__composer-meta">
498499
<div class="context-usage">
499500
<details>
@@ -2403,7 +2404,7 @@ describeBrowserLayout.concurrent("chat responsive browser layout", () => {
24032404
modelLabel: rectFor(".chat-controls__model-trigger .chat-controls__inline-select-label"),
24042405
overrides: rectFor(".agent-chat__session-overrides-pill"),
24052406
status: rectFor(".agent-chat__composer-run-status"),
2406-
typing: rectFor(".agent-chat__typing-indicator"),
2407+
typing: rectFor(".agent-chat__typing-indicator--outside"),
24072408
};
24082409
});
24092410

@@ -2429,16 +2430,29 @@ describeBrowserLayout.concurrent("chat responsive browser layout", () => {
24292430
[layout.status, layout.overrides],
24302431
[layout.overrides, layout.model],
24312432
[layout.model, layout.effort],
2432-
[layout.effort, layout.typing],
2433-
[layout.typing, layout.meta],
2433+
[layout.effort, layout.meta],
24342434
] as const) {
24352435
expect(rectsOverlap(left, right)).toBe(false);
24362436
}
2437+
expect(rectsOverlap(layout.typing, layout.footer)).toBe(false);
24372438
} finally {
24382439
await closeBrowserPage(page);
24392440
}
24402441
});
24412442

2443+
it("keeps the desktop model picker fixed when another user starts typing", async () => {
2444+
const idlePage = await openFixture(1366, 900);
2445+
const typingPage = await openFixture(1366, 900, { typingIndicator: true });
2446+
try {
2447+
const idleModel = await getBoundingBox(idlePage, ".chat-controls__model-trigger");
2448+
const typingModel = await getBoundingBox(typingPage, ".chat-controls__model-trigger");
2449+
2450+
expect(typingModel.x).toBeCloseTo(idleModel.x, 0);
2451+
} finally {
2452+
await Promise.all([closeBrowserPage(idlePage), closeBrowserPage(typingPage)]);
2453+
}
2454+
});
2455+
24422456
it.each([
24432457
[320, 568],
24442458
[393, 852],

‎ui/src/pages/chat/chat-view.test.ts‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,67 @@ function renderChatInto(container: HTMLElement, overrides: Partial<ChatProps> =
748748
render(renderChat(createChatProps(overrides)), container);
749749
}
750750

751+
describe("chat typing status", () => {
752+
it.each([
753+
{
754+
actors: [{ id: "ayaan", label: "Ayaan" }],
755+
expectedText: "Ayaan is typing…",
756+
expectedAvatars: 1,
757+
},
758+
{
759+
actors: [
760+
{ id: "ayaan", label: "Ayaan" },
761+
{ id: "liam", label: "Liam" },
762+
{ id: "maya", label: "Maya" },
763+
{ id: "zoe", label: "Zoe" },
764+
],
765+
expectedText: "Ayaan, Liam, Maya, Zoe are typing…",
766+
expectedAvatars: 3,
767+
},
768+
])("renders $expectedText above the composer", ({ actors, expectedText, expectedAvatars }) => {
769+
const container = renderChatView({ typingActors: actors });
770+
const indicator = container.querySelector(".agent-chat__typing-indicator--outside");
771+
772+
expect(indicator?.nextElementSibling?.classList.contains("agent-chat__composer-shell")).toBe(
773+
true,
774+
);
775+
expect(indicator?.closest(".agent-chat__composer-shell")).toBeNull();
776+
expect(indicator?.querySelectorAll(".chat-author-avatar")).toHaveLength(expectedAvatars);
777+
expect(
778+
indicator?.querySelector(".agent-chat__typing-avatars")?.getAttribute("aria-hidden"),
779+
).toBe("true");
780+
expect(indicator?.textContent).toContain(expectedText);
781+
});
782+
783+
it("keeps queue and error state above the typing status", () => {
784+
const container = renderChatView({
785+
typingActors: [{ id: "ayaan", label: "Ayaan" }],
786+
runError: { summary: "Gateway unavailable" },
787+
queue: [{ id: "queued", text: "Try again", createdAt: 1 }],
788+
});
789+
const indicator = requireElement(
790+
container,
791+
".agent-chat__typing-indicator--outside",
792+
"typing status",
793+
);
794+
795+
expect(indicator.previousElementSibling?.classList.contains("chat-run-error")).toBe(true);
796+
expect(indicator.nextElementSibling?.classList.contains("agent-chat__composer-shell")).toBe(
797+
true,
798+
);
799+
});
800+
801+
it("hides typing status with the model setup composer", () => {
802+
const container = renderChatView({
803+
canSend: false,
804+
modelSetupRequired: true,
805+
typingActors: [{ id: "ayaan", label: "Ayaan" }],
806+
});
807+
808+
expect(container.querySelector(".agent-chat__typing-indicator--outside")).toBeNull();
809+
});
810+
});
811+
751812
function createSessionWorkspace(
752813
overrides: Partial<NonNullable<ChatProps["sessionWorkspace"]>> = {},
753814
): NonNullable<ChatProps["sessionWorkspace"]> {

‎ui/src/pages/chat/components/chat-composer-view.ts‎

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,29 @@ export function renderChatComposerView(context: ChatComposerViewContext) {
155155
</div>
156156
`
157157
: nothing}
158+
${showComposerInput && props.typingActors?.length
159+
? html`<div
160+
class="agent-chat__typing-indicator agent-chat__typing-indicator--outside"
161+
role="status"
162+
>
163+
<!-- Avatars stay aria-hidden: the status text already names every
164+
typer, and role="img" avatars would announce each name twice. -->
165+
<span class="agent-chat__typing-avatars" aria-hidden="true">
166+
${props.typingActors
167+
.slice(0, 3)
168+
.map((actor) => renderChatAuthorAvatar({ id: actor.id, name: actor.label }))}
169+
</span>
170+
<span class="agent-chat__typing-text"
171+
>${props.typingActors.length === 1
172+
? t("chat.sessionSuggestions.typing", {
173+
name: props.typingActors[0]?.label ?? "",
174+
})
175+
: t("chat.sessionSuggestions.typingMany", {
176+
names: props.typingActors.map((actor) => actor.label).join(", "),
177+
})}</span
178+
>
179+
</div>`
180+
: nothing}
158181
<div class="agent-chat__composer-shell">
159182
${questionPanelProps
160183
? html`
@@ -484,28 +507,6 @@ export function renderChatComposerView(context: ChatComposerViewContext) {
484507
</div>
485508
`
486509
: nothing}
487-
${props.typingActors?.length
488-
? html`<div class="agent-chat__typing-indicator" role="status">
489-
<!-- Avatars stay aria-hidden: the status text already names every
490-
typer, and role="img" avatars would announce each name twice. -->
491-
<span class="agent-chat__typing-avatars" aria-hidden="true">
492-
${props.typingActors
493-
.slice(0, 3)
494-
.map((actor) =>
495-
renderChatAuthorAvatar({ id: actor.id, name: actor.label }),
496-
)}
497-
</span>
498-
<span class="agent-chat__typing-text"
499-
>${props.typingActors.length === 1
500-
? t("chat.sessionSuggestions.typing", {
501-
name: props.typingActors[0]?.label ?? "",
502-
})
503-
: t("chat.sessionSuggestions.typingMany", {
504-
names: props.typingActors.map((actor) => actor.label).join(", "),
505-
})}</span
506-
>
507-
</div>`
508-
: nothing}
509510
<div class="agent-chat__composer-meta">${contextNotice}</div>
510511
</div>
511512
</div>`

‎ui/src/styles/chat/layout.css‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,6 +1756,14 @@ button.chat-reply-preview--message:disabled {
17561756
white-space: nowrap;
17571757
}
17581758

1759+
.agent-chat__typing-indicator--outside {
1760+
box-sizing: border-box;
1761+
width: calc(100% - 36px);
1762+
max-width: var(--chat-thread-max-width, 48rem);
1763+
margin: 0 auto -2px;
1764+
padding-inline: 8px;
1765+
}
1766+
17591767
@media (max-width: 640px) {
17601768
.session-suggestion {
17611769
grid-template-columns: auto minmax(0, 1fr);
@@ -3718,11 +3726,6 @@ button.chat-reply-preview--message:disabled {
37183726
min-width: 44px;
37193727
}
37203728

3721-
.agent-chat__input .agent-chat__typing-indicator {
3722-
flex: 1 1 auto;
3723-
overflow: hidden;
3724-
}
3725-
37263729
/* The borderless trigger is 30px on desktop; keep a >=44px touch target
37273730
inside the mobile composer row. */
37283731
.agent-chat__input .agent-chat__composer-controls .chat-controls__inline-select-trigger {

0 commit comments

Comments
 (0)