Skip to content

Commit dc0a681

Browse files
mahanticodex
andauthored
Polish message hover fills and shorten tooltip delays (#1993)
Signed-off-by: Arjun Mahanti <[email protected]> Co-authored-by: Codex <[email protected]>
1 parent 89e2d15 commit dc0a681

11 files changed

Lines changed: 119 additions & 44 deletions

File tree

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,19 +2921,22 @@ html[data-keyboard-navigation] .rawDiff:focus-visible {
29212921
color: var(--text-standard);
29222922
overflow-wrap: anywhere;
29232923
}
2924-
/* Own bubbles retain their toolbar hover treatment; received bubbles stay
2925-
on the same quiet surface as their reaction strip. */
29262924
@media (hover: hover) and (pointer: fine) {
2925+
.message[data-actions-revealed]
2926+
> .messageBody
2927+
> .messageContent
2928+
.messageBubble:not([data-emoji-only], [data-diff-only]):not(
2929+
:has(> .text > table:only-child)
2930+
) {
2931+
background: var(--surface-message-hover);
2932+
}
29272933
.message[data-own][data-actions-revealed]
29282934
> .messageBody
29292935
> .messageContent
2930-
.messageBubble:not([data-emoji-only])::after {
2931-
content: "";
2932-
position: absolute;
2933-
inset: 0;
2934-
border-radius: inherit;
2935-
background: var(--affordance-message-own-hover);
2936-
pointer-events: none;
2936+
.messageBubble:not([data-emoji-only], [data-diff-only]):not(
2937+
:has(> .text > table:only-child)
2938+
) {
2939+
background: var(--surface-message-own-hover);
29372940
}
29382941
}
29392942
.message[data-layout="continuation"] .messageBubble {
@@ -3523,10 +3526,6 @@ html[data-keyboard-navigation]
35233526
margin-inline-start: 0;
35243527
max-width: 100%;
35253528
}
3526-
.messageBubble[data-diff-only]::after,
3527-
.messageBubble:has(> .text > table:only-child)::after {
3528-
display: none;
3529-
}
35303529
.workflowAttribution {
35313530
display: inline-flex;
35323531
align-items: baseline;

‎src/shared/design-system/DESIGN.md‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,15 +310,15 @@ surface belongs to exactly one bucket, and the timings live in
310310
timing, change the bucket for everyone.
311311

312312
Inside an open menu, submenus open immediately. A side explanation for grouped
313-
unavailable choices uses `PopoverTrigger openOnHover="control"` (0.1s). Keep
313+
unavailable choices uses `PopoverTrigger openOnHover="control"` (0.05s). Keep
314314
each disabled choice keyboard reachable and connected to the shared description.
315315

316316
| Bucket | Use for | Timing | API |
317317
| --- | --- | --- | --- |
318-
| Familiar hint | Naming an icon whose meaning is already obvious: back/forward, close, window controls, sidebar and pane toggles, new (+), more (…), send, attach, copy, download, refresh, delete, mute, reply, add reaction, bold/italic. An obvious icon stays familiar when its hint also shows a shortcut; a disabled one switches to helpful | Rests 1.5s | `Tooltip hint="familiar"`; `Button`/`IconButton` `title` with `hint="familiar"` |
319-
| Helpful hint | Naming an icon people may not recognize, or adding information the control does not show: an unfamiliar control’s shortcut, why it is disabled (use Hover control for side explanations of grouped unavailable choices in an open menu), an error, a truncated value | Rests 0.5s | `Tooltip`, or `title` on `Button`/`IconButton` (the default) |
320-
| Preview | Rich content about an object: a profile, link, channel, activity, typing participants, who reacted | Rests 0.6s | `PreviewCard`; `PopoverTrigger openOnHover="preview"` |
321-
| Hover control | A control that expands in place under the pointer: video volume, playback speed; side explanations for grouped unavailable choices in an open menu | Rests 0.1s | `PopoverTrigger` or `MenuTrigger` with `openOnHover="control"` |
318+
| Familiar hint | Naming an icon whose meaning is already obvious: back/forward, close, window controls, sidebar and pane toggles, new (+), more (…), send, attach, copy, download, refresh, delete, mute, reply, add reaction, bold/italic. An obvious icon stays familiar when its hint also shows a shortcut; a disabled one switches to helpful | Rests 0.5s | `Tooltip hint="familiar"`; `Button`/`IconButton` `title` with `hint="familiar"` |
319+
| Helpful hint | Naming an icon people may not recognize, or adding information the control does not show: an unfamiliar control’s shortcut, why it is disabled (use Hover control for side explanations of grouped unavailable choices in an open menu), an error, a truncated value | Rests 0.25s | `Tooltip`, or `title` on `Button`/`IconButton` (the default) |
320+
| Preview | Rich content about an object: a profile, link, channel, activity, typing participants, who reacted | Rests 0.3s | `PreviewCard`; `PopoverTrigger openOnHover="preview"` |
321+
| Hover control | A control that expands in place under the pointer: video volume, playback speed; side explanations for grouped unavailable choices in an open menu | Rests 0.05s | `PopoverTrigger` or `MenuTrigger` with `openOnHover="control"` |
322322
| No hover | A control whose visible text already says what it does | None | Omit `title` |
323323

324324
Hints share the app's `TooltipProvider`: once one is showing, its neighbors open
@@ -1794,10 +1794,10 @@ the same overlay again on top of the strip. Inside your bubble reactions take
17941794
its ink and `affordance-reaction-own`; outside it, under an emoji-only message,
17951795
they keep the standard ink and overlay of the panel they sit on.
17961796

1797-
Hovering your own message lays a quieter overlay across the whole bubble
1798-
(`affordance-message-own-hover`: black 4% or white 8%), in the same direction as
1799-
its chips, so a bright bubble never takes a white wash in dark mode. Received
1800-
bubbles keep the quiet surface their reaction strip shares and take no hover.
1797+
When message actions show, both received and own bubbles use their
1798+
`surface-message-hover` or `surface-message-own-hover` fill: 5% toward black in
1799+
light mode and 5% toward white in dark mode. This changes only the background,
1800+
without a stroke or an overlay on text and media. Emoji-only messages stay clear.
18011801

18021802
These pairs have no link-specific contrast exemptions.
18031803
The contrast guard checks APCA and WCAG AA (4.5:1) on opaque text pairs, including

‎src/shared/design-system/styles/tokens.css‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,10 @@
10911091
--text-on-selection-own: var(--neutral-1);
10921092
--surface-message: var(--bubble-received);
10931093
--surface-message-own: var(--bubble-neutral);
1094+
--surface-message-hover: var(--bubble-hover);
1095+
--surface-message-own-hover: var(--bubble-own-hover);
1096+
--bubble-hover: color-mix(in srgb, var(--surface-message) 95%, black);
1097+
--bubble-own-hover: color-mix(in srgb, var(--surface-message-own) 95%, black);
10941098
--text-message-own: var(--text-standard);
10951099
--text-message-link-own: var(--text-link);
10961100
--affordance-message-own-hover: var(--shade-quiet-fill);
@@ -1221,6 +1225,10 @@
12211225
.dark {
12221226
--surface-message: var(--bubble-received);
12231227
--surface-message-own: var(--bubble-neutral);
1228+
--surface-message-hover: var(--bubble-hover);
1229+
--surface-message-own-hover: var(--bubble-own-hover);
1230+
--bubble-hover: color-mix(in srgb, var(--surface-message) 95%, white);
1231+
--bubble-own-hover: color-mix(in srgb, var(--surface-message-own) 95%, white);
12241232
--text-message-own: var(--text-standard);
12251233
--text-message-link-own: var(--text-link);
12261234
--affordance-message-own-hover: var(--tint-quiet-fill);

‎src/shared/design-system/tokens/registry.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,22 @@ export const ROLE_GROUPS: RoleGroup[] = [
360360
use: "Own message bubbles; pair with --text-message-own.",
361361
status: "core",
362362
},
363+
{
364+
token: "bg-surface-message-hover",
365+
variable: "--surface-message-hover",
366+
pointsAt:
367+
"surface-message mixed 5% toward black in light mode / white in dark mode",
368+
use: "Received bubble fill while its actions show; text and media are unchanged.",
369+
status: "core",
370+
},
371+
{
372+
token: "bg-surface-message-own-hover",
373+
variable: "--surface-message-own-hover",
374+
pointsAt:
375+
"surface-message-own mixed 5% toward black in light mode / white in dark mode",
376+
use: "Own bubble fill while its actions show; text and media are unchanged.",
377+
status: "core",
378+
},
363379
{
364380
token: "--affordance-message-own-hover",
365381
variable: "--affordance-message-own-hover",

‎src/shared/design-system/ui/hoverIntent.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
* DESIGN.md "Hover timing" assigns each surface to one of these buckets.
55
*/
66
/** Hints that add information or name an unfamiliar icon. */
7-
export const HELPFUL_HINT_REST_MS = 500;
7+
export const HELPFUL_HINT_REST_MS = 250;
88
/** Hints naming an icon whose meaning is already obvious. */
9-
export const FAMILIAR_HINT_REST_MS = 1500;
9+
export const FAMILIAR_HINT_REST_MS = 500;
1010
/** Rich previews cover more of the page, so they wait longer than a hint. */
11-
export const PREVIEW_REST_MS = 600;
11+
export const PREVIEW_REST_MS = 300;
1212
/** Controls that expand in place under the pointer, such as video volume. */
13-
export const HOVER_CONTROL_REST_MS = 100;
13+
export const HOVER_CONTROL_REST_MS = 50;
1414

1515
/** A bucket for a popover or menu that opens on hover. */
1616
export type HoverOpen = "preview" | "control";
1717

1818
/** Rest before opening and grace before closing, per hover-opening bucket. */
1919
export const hoverOpenTiming = {
20-
preview: { delay: PREVIEW_REST_MS, closeDelay: 150 },
21-
control: { delay: HOVER_CONTROL_REST_MS, closeDelay: 100 },
20+
preview: { delay: PREVIEW_REST_MS, closeDelay: 75 },
21+
control: { delay: HOVER_CONTROL_REST_MS, closeDelay: 50 },
2222
} satisfies Record<HoverOpen, { delay: number; closeDelay: number }>;

‎tests/browser/history-loading.spec.mjs‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,22 @@ test.describe("pages inside one second", () => {
355355
const row = history(page).locator(`[data-message-id="${held.id}"]`);
356356
const seen = await history(page).evaluateHandle((e, id) => {
357357
const seen = { unmounted: false };
358-
new MutationObserver(() => {
359-
if (!e.querySelector(`[data-message-id="${id}"]`))
358+
const heldRow = e.querySelector(`[data-message-id="${id}"]`);
359+
const observer = new MutationObserver((records) => {
360+
// Read the removals themselves: the row may already be remounted
361+
// when the observer delivers a batch of mutations.
362+
if (
363+
records.some((record) =>
364+
Array.from(record.removedNodes).some((node) =>
365+
node.contains(heldRow),
366+
),
367+
)
368+
) {
360369
seen.unmounted = true;
361-
}).observe(e, { childList: true, subtree: true });
370+
observer.disconnect();
371+
}
372+
});
373+
observer.observe(e, { childList: true, subtree: true });
362374
e.scrollTop -= e.clientHeight + 150;
363375
return seen;
364376
}, held.id);
@@ -378,14 +390,16 @@ test.describe("pages inside one second", () => {
378390
const before = await anchor(page);
379391
// The row above it finishes measuring taller (an image loading). Rows
380392
// below the reader grow away from them; nothing in view moves.
381-
await history(page).evaluate((e, id) => {
393+
// Re-resolve the virtualized row at mutation time: an idle render may
394+
// have unmounted it again since the position assertion above.
395+
await row.evaluate((element) => {
382396
const extra = document.createElement("div");
383397
extra.style.height = "300px";
384-
e.querySelector(`[data-message-id="${id}"]`)
398+
element
385399
.closest("li")
386400
.previousElementSibling.querySelector("[data-message-id] p")
387401
.after(extra);
388-
}, held.id);
402+
});
389403
await settle(page);
390404
await expectAnchor(page, before);
391405
} finally {

‎tests/browser/mention-selection.spec.mjs‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -404,13 +404,23 @@ test("selection remains visible on outgoing bubbles and their neutral content",
404404
while (getComputedStyle(parent).backgroundColor === "rgba(0, 0, 0, 0)")
405405
parent = parent.parentElement;
406406
const selection = getComputedStyle(el, "::selection");
407-
const hex = (rgb) =>
408-
"#" +
409-
rgb
410-
.match(/\d+/g)
411-
.slice(0, 3)
412-
.map((n) => Number(n).toString(16).padStart(2, "0"))
413-
.join("");
407+
// WebKit serializes mixed hover fills as color(srgb ...), not rgb().
408+
// Let the browser resolve CSS colors before comparing the same ratios.
409+
const canvas = document.createElement("canvas");
410+
canvas.width = canvas.height = 1;
411+
const context = canvas.getContext("2d");
412+
const hex = (color) => {
413+
context.clearRect(0, 0, 1, 1);
414+
context.fillStyle = color;
415+
context.fillRect(0, 0, 1, 1);
416+
return (
417+
"#" +
418+
[...context.getImageData(0, 0, 1, 1).data]
419+
.slice(0, 3)
420+
.map((value) => value.toString(16).padStart(2, "0"))
421+
.join("")
422+
);
423+
};
414424
return {
415425
surface: hex(getComputedStyle(parent).backgroundColor),
416426
fill: hex(selection.backgroundColor),

‎tests/browser/message-content-polish.spec.mjs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,23 @@ test("reactions under an unboxed own table stay contained and readable", async (
9090
}
9191
});
9292

93+
for (const theme of ["light", "dark"]) {
94+
test(`standalone table and diff hover stays transparent in ${theme}`, async ({
95+
page,
96+
}) => {
97+
await page.goto(
98+
`/tests/fixtures/message-gallery.html?group=references&theme=${theme}`,
99+
);
100+
for (const id of ["table-received", "table-links", "code-diff"]) {
101+
const example = specimen(page, id);
102+
const bubble = example.locator("[data-message-action-anchor]");
103+
await bubble.hover();
104+
await expect(example.locator("[data-actions-revealed]")).toBeVisible();
105+
await expect(bubble).toHaveCSS("background-color", "rgba(0, 0, 0, 0)");
106+
}
107+
});
108+
}
109+
93110
for (const theme of ["light", "dark"]) {
94111
test(`message references and inset surfaces remain legible in ${theme}`, async ({
95112
page,

‎tests/browser/profiles.spec.mjs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,10 @@ test("profile plumbing: exact avatar/mention targets, thread enrichment, lifecyc
432432
if (pointerVisit === "back") {
433433
const rect = await avatar.boundingBox();
434434
await page.mouse.move(rect.x + rect.width / 2, rect.y + rect.height / 2);
435+
// Complete this hover while Profile is still open. Otherwise its timer
436+
// can fire after Escape and legitimately count as a fresh hover visit.
437+
await page.clock.runFor(300);
438+
await expect(preview).toBeHidden();
435439
}
436440
await page.getByRole("region", { name: "Profile details" }).press("Escape");
437441
await expect(panel).toHaveCount(0);

‎tests/browser/reactions-polish.spec.mjs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,10 @@ test("reaction previews use the delayed first open, immediate warm switch, and r
477477
await page.clock.install({ time: new Date("2026-01-01T00:00:00Z") });
478478
await page.clock.pauseAt(new Date("2026-01-01T00:00:10Z"));
479479
try {
480-
// Previews wait for the pointer to rest 0.6s (DESIGN.md "Hover timing").
480+
// Previews wait for the pointer to rest 0.3s (DESIGN.md "Hover timing").
481481
await custom.hover();
482482
await expect(tooltip).toHaveCount(0);
483-
await page.clock.runFor(599);
483+
await page.clock.runFor(299);
484484
await expect(tooltip).toHaveCount(0);
485485
await page.clock.runFor(1);
486486
await expect(tooltip).toBeVisible();
@@ -490,7 +490,7 @@ test("reaction previews use the delayed first open, immediate warm switch, and r
490490
await expect(tooltip).toHaveCount(0);
491491
await page.clock.runFor(151);
492492
await custom.hover();
493-
await page.clock.runFor(599);
493+
await page.clock.runFor(299);
494494
await expect(tooltip).toHaveCount(0);
495495
await page.clock.runFor(1);
496496
await expect(tooltip).toBeVisible();

0 commit comments

Comments
 (0)