Skip to content

Commit 85c7f39

Browse files
wesbillmanCarl
andauthored
Polish composer typing indicators (#551)
Signed-off-by: Carl <32a2e2c9d428ee08902cab75d956da2c1d235a22d4766b0dd4138bf6e2e5db1d@buzz.block.builderlab.xyz> Co-authored-by: Carl <32a2e2c9d428ee08902cab75d956da2c1d235a22d4766b0dd4138bf6e2e5db1d@buzz.block.builderlab.xyz>
1 parent e6425ca commit 85c7f39

10 files changed

Lines changed: 226 additions & 45 deletions

‎src/features/messages/MessageComposer.test.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,6 +2012,7 @@ it("keeps retry submission available while a new-session draft is locked", () =>
20122012
submit,
20132013
},
20142014
});
2015+
expect(document.querySelector("[data-reserve-typing]")).toBeNull();
20152016
expect(h.input()).toHaveAttribute("aria-disabled", "true");
20162017
const send = screen.getByRole("button", { name: "Send message" });
20172018
expect(send).toBeEnabled();

‎src/features/messages/MessageComposer.tsx‎

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -913,16 +913,31 @@ function Composer({
913913
}
914914
}
915915
}
916-
const accessories = extensions?.accessories && (
917-
<ComposerAccessories
918-
registry={extensions.accessories}
919-
session={session}
920-
scope={scope}
921-
channelId={channelId}
922-
threadRootId={threadRootId}
923-
canOpen={(target) => canOpenLink?.(target) ?? false}
924-
open={(target) => onOpenLink?.(target) ?? false}
925-
/>
916+
const readingOnly = !outbox?.supports(9) && !cached;
917+
const context = (
918+
<div
919+
className={styles.composerContext}
920+
data-reserve-typing={!submission || readingOnly || undefined}
921+
>
922+
{readingOnly || (!disabled && !submission && !editing.target) ? (
923+
<TypingIndicator
924+
session={session}
925+
channelId={channelId}
926+
threadRootId={threadRootId}
927+
/>
928+
) : null}
929+
{extensions?.accessories && (
930+
<ComposerAccessories
931+
registry={extensions.accessories}
932+
session={session}
933+
scope={scope}
934+
channelId={channelId}
935+
threadRootId={threadRootId}
936+
canOpen={(target) => canOpenLink?.(target) ?? false}
937+
open={(target) => onOpenLink?.(target) ?? false}
938+
/>
939+
)}
940+
</div>
926941
);
927942
const renderLeadingTools = (tools: ReactNode) => (
928943
<>
@@ -963,23 +978,18 @@ function Composer({
963978
)}
964979
</>
965980
);
966-
if (!outbox?.supports(9) && !cached)
981+
if (readingOnly)
967982
return (
968983
<>
969-
{accessories}
984+
{context}
970985
<footer className={styles.composer}>
971-
<TypingIndicator
972-
session={session}
973-
channelId={channelId}
974-
threadRootId={threadRootId}
975-
/>
976986
This relay connection supports reading only.
977987
</footer>
978988
</>
979989
);
980990
return (
981991
<SelectedMentionContext.Provider value={value.recipients}>
982-
{accessories}
992+
{context}
983993
{active && nonmembers.dialog}
984994
<form
985995
ref={form}
@@ -1036,13 +1046,6 @@ function Composer({
10361046
/>
10371047
</div>
10381048
)}
1039-
{!disabled && !submission && !editing.target && (
1040-
<TypingIndicator
1041-
session={session}
1042-
channelId={channelId}
1043-
threadRootId={threadRootId}
1044-
/>
1045-
)}
10461049
<label className="sr-only" htmlFor={inputId}>
10471050
{label}
10481051
</label>

‎src/features/messages/Messages.module.css‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,18 @@ html[data-keyboard-navigation] .attachmentImage:focus-visible {
460460
background: var(--affordance-subtle-hover);
461461
color: var(--text-subtle);
462462
}
463+
/* Keep public typing and plugin accessories in one non-collapsing stack. */
464+
.composerContext {
465+
position: relative;
466+
display: flex;
467+
flex-direction: column;
468+
flex-shrink: 0;
469+
min-width: 0;
470+
}
471+
/* Existing conversations keep a fixed row, even while nobody is typing. */
472+
.composerContext[data-reserve-typing] {
473+
padding-top: var(--space-6);
474+
}
463475
/* The existing editor owns text; this surface owns only composer layout. */
464476
.composer {
465477
--composer-gap: var(--space-4);
Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,74 @@
11
.typing {
2-
height: 0;
3-
margin-bottom: calc(-1 * var(--composer-gap, var(--space-1)));
4-
flex-shrink: 0;
5-
overflow: visible;
6-
color: var(--text-muted);
2+
/* The composer context reserves this row even while typing is idle. */
3+
position: absolute;
4+
inset-inline: calc(var(--space-4) + var(--space-2));
5+
top: 0;
6+
display: flex;
7+
align-items: center;
8+
gap: var(--space-1h);
9+
width: fit-content;
10+
max-width: calc(100% - 2 * (var(--space-4) + var(--space-2)));
11+
pointer-events: none;
12+
box-sizing: border-box;
13+
padding: var(--space-half) var(--space-1h);
14+
border-radius: var(--radius-pill);
15+
background: var(--surface-panel);
16+
color: var(--text-subtle);
717
font-size: var(--text-caption);
8-
line-height: 1.5;
18+
line-height: var(--text-caption--line-height);
19+
letter-spacing: var(--text-caption--letter-spacing);
20+
font-weight: var(--text-caption--font-weight);
21+
}
22+
23+
.label {
24+
min-width: 0;
25+
overflow: hidden;
926
white-space: nowrap;
1027
text-overflow: ellipsis;
11-
transform: translateY(calc(-1lh - var(--space-2)));
28+
}
29+
30+
.names {
31+
color: var(--text-standard);
32+
font-weight: var(--type-weight-medium);
33+
}
34+
35+
.dots {
36+
display: flex;
37+
flex-shrink: 0;
38+
align-items: center;
39+
gap: var(--space-half);
40+
}
41+
42+
.dots > span {
43+
width: var(--space-1);
44+
height: var(--space-1);
45+
border-radius: 50%;
46+
background: currentColor;
47+
}
48+
49+
@keyframes typing-pulse {
50+
50% {
51+
opacity: 0.35;
52+
}
53+
}
54+
55+
@media (prefers-reduced-motion: no-preference) {
56+
.dots > span {
57+
animation: typing-pulse 1.4s ease-in-out infinite;
58+
}
59+
60+
.dots > span:nth-child(2) {
61+
animation-delay: 0.2s;
62+
}
63+
64+
.dots > span:nth-child(3) {
65+
animation-delay: 0.4s;
66+
}
67+
}
68+
69+
@media (max-width: 40.625rem) {
70+
.typing {
71+
inset-inline: calc(var(--space-3) + var(--space-2));
72+
max-width: calc(100% - 2 * (var(--space-3) + var(--space-2)));
73+
}
1274
}

‎src/features/messages/TypingIndicator.tsx‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,16 @@ export function TypingIndicator({
3535
);
3636
const others = matching.length - names.length;
3737
return (
38-
<div className={styles.typing}>
39-
<span role="status" aria-label="Typing activity">
40-
{names.join(", ")}
38+
<div className={styles.typing} role="status" aria-label="Typing activity">
39+
<span className={styles.dots} aria-hidden="true">
40+
<span />
41+
<span />
42+
<span />
43+
</span>
44+
<span className={styles.label}>
45+
<span className={styles.names}>{names.join(", ")}</span>
4146
{others > 0 ? ` and ${others} others` : ""}
42-
{matching.length === 1 ? " is typing…" : " are typing…"}
47+
{matching.length === 1 ? " is typing" : " are typing"}
4348
</span>
4449
</div>
4550
);

‎tests/browser/agent-activity.spec.mjs‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,8 +838,14 @@ test.describe("thread activity", () => {
838838
element.getAnimations().map((animation) => animation.finished),
839839
);
840840
});
841+
const typingIndicator = thread.getByRole("status", {
842+
name: "Typing activity",
843+
});
844+
await expect(typingIndicator).toBeVisible();
841845
const entryBox = await entry.boundingBox(),
842-
formBox = await form.boundingBox();
846+
formBox = await form.boundingBox(),
847+
typingBox = await typingIndicator.boundingBox();
848+
expect(typingBox.y + typingBox.height).toBeLessThan(entryBox.y);
843849
expect(entryBox.y + entryBox.height).toBeLessThanOrEqual(formBox.y);
844850
expect(formBox.y - entryBox.y - entryBox.height).toBeCloseTo(4, 0);
845851
const inset = await entry.evaluate((element) =>
@@ -868,8 +874,15 @@ test.describe("thread activity", () => {
868874
await expect
869875
.poll(() => page.evaluate(() => document.documentElement.scrollWidth))
870876
.toBe(390);
877+
await expect(typingIndicator).toBeVisible();
871878
const narrowEntry = await entry.boundingBox(),
872-
narrowForm = await form.boundingBox();
879+
narrowForm = await form.boundingBox(),
880+
narrowTyping = await typingIndicator.boundingBox();
881+
expect(narrowTyping.y + narrowTyping.height).toBeLessThan(narrowEntry.y);
882+
expect(narrowTyping.x).toBeGreaterThanOrEqual(narrowForm.x);
883+
expect(narrowTyping.x + narrowTyping.width).toBeLessThanOrEqual(
884+
narrowForm.x + narrowForm.width,
885+
);
873886
expect(narrowEntry.y + narrowEntry.height).toBeLessThanOrEqual(
874887
narrowForm.y,
875888
);
@@ -910,6 +923,15 @@ test.describe("thread activity", () => {
910923
const channelForm = await page
911924
.getByRole("form", { name: "Send a message to Alpha", exact: true })
912925
.boundingBox();
926+
const channelTyping = page
927+
.getByRole("form", { name: "Send a message to Alpha", exact: true })
928+
.locator("..")
929+
.getByRole("status", { name: "Typing activity" });
930+
await expect(channelTyping).toBeVisible();
931+
const channelTypingBox = await channelTyping.boundingBox();
932+
expect(channelTypingBox.y + channelTypingBox.height).toBeLessThan(
933+
channelBox.y,
934+
);
913935
expect(channelBox.y + channelBox.height).toBeLessThanOrEqual(channelForm.y);
914936
await expect(marker).toHaveCount(0, { timeout: 10_000 });
915937
await expect(channelActivity(page)).toHaveCount(0);

‎tests/browser/inbox-drafts.spec.mjs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ test("keyboard draft retirement returns to its row, a remaining row, then Back t
394394
const inbox = page.getByRole("region", { name: "Inbox", exact: true });
395395
await expect(inbox.getByText("Checking recent activity…")).toHaveCount(0);
396396
const activate = async (control) => {
397+
// focus() does not wait for enabled state while the draft root loads.
398+
await expect(control).toBeEnabled();
397399
await control.focus();
398400
await expect(control).toBeFocused();
399401
await page.keyboard.press("Enter");

‎tests/browser/media-controls.spec.mjs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ for (const kind of ["image", "video"]) {
5050
}
5151
for (const width of [320, 800, 1280]) {
5252
await page.setViewportSize({ width, height: 720 });
53+
if (kind === "video") {
54+
await page.evaluate(() =>
55+
window.dispatchEvent(new Event("fixture-typing")),
56+
);
57+
const typing = dialog.getByRole("status", { name: "Typing activity" });
58+
const frameOption = dialog.getByRole("checkbox", {
59+
name: "Comment at current frame",
60+
});
61+
await expect(typing).toContainText("Alex is typing");
62+
const typingBox = await typing.boundingBox();
63+
const optionBox = await frameOption.boundingBox();
64+
expect(typingBox.y).toBeGreaterThan(optionBox.y + optionBox.height);
65+
}
5366
const control = dialog.getByRole("button", {
5467
name: kind === "image" ? /^Image zoom:/ : "Play video",
5568
exact: true,

‎tests/browser/typing.spec.mjs‎

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,24 @@ test("Messages receives scoped typing through authenticated live traffic and exp
2323
app.activity({ age: 9 });
2424
await expect(indicator).toHaveCount(0);
2525
app.activity();
26-
await expect(indicator).toContainText("is typing…");
26+
await expect(indicator).toContainText("is typing");
2727
app.activity({ author: 1 });
28-
await expect(indicator).toContainText("are typing…");
28+
await expect(indicator).toContainText("are typing");
29+
await expect(indicator).not.toContainText("…");
30+
// Browser-only contracts: real geometry and the OS motion preference.
31+
const composer = page.getByRole("form", { name: "Send a message to Alpha" });
32+
const bounds = await indicator.boundingBox();
33+
const composerBounds = await composer.boundingBox();
34+
expect(bounds.y + bounds.height).toBeLessThan(composerBounds.y);
35+
const dots = indicator.locator('[aria-hidden="true"] > span');
36+
await expect(dots).toHaveCount(3);
37+
await page.emulateMedia({ reducedMotion: "no-preference" });
38+
await expect(dots.first()).not.toHaveCSS("animation-name", "none");
39+
await page.emulateMedia({ reducedMotion: "reduce" });
40+
await expect(dots.first()).toHaveCSS("animation-name", "none");
2941
await page.screenshot({ path: testInfo.outputPath("messages-typing.png") });
3042
app.activity({ kind: 9 });
31-
await expect(indicator).toContainText("is typing…");
43+
await expect(indicator).toContainText("is typing");
3244
app.activity({ kind: 9, author: 1 });
3345
await expect(indicator).toHaveCount(0);
3446
app.activity(); // same-second late pulse cannot resurrect completion
@@ -55,11 +67,33 @@ test("Messages receives scoped typing through authenticated live traffic and exp
5567
app.activity({ root: root.id });
5668
await expect(
5769
thread.getByRole("status", { name: "Typing activity" }),
58-
).toContainText("is typing…");
70+
).toContainText("is typing");
5971
await expect(indicator).toHaveCount(1);
6072
await page.screenshot({
6173
path: testInfo.outputPath("messages-thread-typing.png"),
6274
});
75+
await page.emulateMedia({ colorScheme: "dark" });
76+
await page.setViewportSize({ width: 800, height: 700 });
77+
// Stress the real label's CSS with an unbroken name, without adding profile
78+
// fixture/network machinery to a presentation-only regression.
79+
const label = indicator.locator(":scope > span").last();
80+
await label.evaluate((el) => {
81+
el.textContent = `${"LongDisplayName".repeat(30)} is typing`;
82+
});
83+
await expect(label).toHaveCSS("text-overflow", "ellipsis");
84+
expect(await label.evaluate((el) => el.scrollWidth > el.clientWidth)).toBe(
85+
true,
86+
);
87+
const narrowBounds = await indicator.boundingBox();
88+
const threadComposer = await thread.getByRole("form").boundingBox();
89+
expect(narrowBounds.x).toBeGreaterThanOrEqual(threadComposer.x);
90+
expect(narrowBounds.x + narrowBounds.width).toBeLessThanOrEqual(
91+
threadComposer.x + threadComposer.width,
92+
);
93+
expect(narrowBounds.y + narrowBounds.height).toBeLessThan(threadComposer.y);
94+
await page.screenshot({
95+
path: testInfo.outputPath("messages-thread-typing-dark-narrow.png"),
96+
});
6397
// Real browser timer, signed timestamp TTL, no polling transport or fixture cleanup.
6498
await expect(indicator).toHaveCount(0, { timeout: 10000 });
6599
expect(app.report.publications).toEqual([]);
@@ -105,7 +139,9 @@ for (const scope of ["channel", "thread"]) {
105139
name: scope === "thread" ? "Reply to thread" : "Send a message to Alpha",
106140
exact: true,
107141
});
108-
const indicator = composer.getByRole("status", { name: "Typing activity" });
142+
const indicator = composer
143+
.locator("..")
144+
.getByRole("status", { name: "Typing activity" });
109145
const gap = () =>
110146
history.evaluate(
111147
(el) => el.scrollHeight - el.clientHeight - el.scrollTop,
@@ -141,14 +177,16 @@ for (const scope of ["channel", "thread"]) {
141177
await expect(indicator).toHaveCount(0);
142178
const target = scope === "thread" ? { root: root.id } : {};
143179
app.activity(target);
144-
await expect(indicator).toContainText("is typing…");
180+
await expect(indicator).toContainText("is typing");
181+
const typingBounds = await indicator.boundingBox();
182+
expect(typingBounds.y).toBeGreaterThanOrEqual(idle.y + idle.height);
145183
await stable();
146184
app.activity({ ...target, kind: 9 });
147185
await expect(indicator).toHaveCount(0);
148186
await stable();
149187
// A different signer is outside the first signer's quiet period.
150188
app.activity({ ...target, author: 1 });
151-
await expect(indicator).toContainText("is typing…");
189+
await expect(indicator).toContainText("is typing");
152190
await stable();
153191
await expect(indicator).toHaveCount(0, { timeout: 10000 });
154192
await stable();

0 commit comments

Comments
 (0)