Skip to content

Commit 361bed5

Browse files
authored
fix(session-ui): light the whole Compacted label on hover (#65644)
1 parent f55e257 commit 361bed5

5 files changed

Lines changed: 109 additions & 17 deletions

File tree

‎packages/session-ui/component-tests/session-compaction.spec.ts‎

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,22 @@ story("shows a running automatic compaction as one Compacting divider", async ({
2121
await expect(message.locator('[data-component="text-part"]')).toHaveCount(0)
2222
})
2323

24-
story("opens a finished automatic compaction's summary from its divider", async ({ mount }) => {
24+
story("opens a finished automatic compaction's summary from its divider", async ({ mount, page }) => {
2525
const timeline = await mount(`${rows}--compaction-and-continuation`)
2626
const message = timeline.locator('[data-component="session-compaction-message"]')
2727
const divider = message.locator('[data-slot="session-compaction-divider"]')
2828
const summary = message.locator('[data-slot="session-compaction-summary"]')
2929

30+
// The stem Compacting and Compacted share, then the ending that differs.
31+
const colors = () =>
32+
message.locator('[data-slot="session-compaction-label"]').evaluate((label) =>
33+
[label.firstElementChild, label.querySelector('[data-slot="session-compaction-done"]')].map((part) => {
34+
if (!part) throw new Error("Expected the label's stem and ending")
35+
36+
return getComputedStyle(part).color
37+
}),
38+
)
39+
3040
// Loaded with the history, so it is already there rather than fading in.
3141
await expect(message).not.toHaveAttribute("data-enter")
3242
await expect(divider).toHaveAttribute("data-state", "done")
@@ -35,12 +45,22 @@ story("opens a finished automatic compaction's summary from its divider", async
3545
await expect(divider).toHaveAttribute("aria-expanded", "false")
3646
await expect(divider).not.toHaveAttribute("aria-controls")
3747
await expect(summary).toHaveCount(0)
48+
const [rest] = await colors()
49+
50+
// Hovering lights the whole word, not only the ending.
51+
await divider.hover()
52+
await expect.poll(async () => (await colors())[0]).not.toBe(rest)
53+
await expect.poll(async () => new Set(await colors()).size).toBe(1)
3854

3955
await divider.click()
4056
await expect(divider).toHaveAttribute("aria-expanded", "true")
4157
await expect(summary).toContainText("The Session timeline now consumes current nested assistant content.")
4258
await expect(summary).toContainText("11.9K in · 508 out")
4359
await expect(divider).toHaveAttribute("aria-controls", (await summary.getAttribute("id")) ?? "")
60+
// An open divider keeps the whole word lit once the pointer leaves.
61+
await page.mouse.move(0, 0)
62+
await expect.poll(async () => (await colors())[0]).not.toBe(rest)
63+
await expect.poll(async () => new Set(await colors()).size).toBe(1)
4464

4565
await divider.click()
4666
await expect(divider).toHaveAttribute("aria-expanded", "false")
@@ -127,6 +147,46 @@ story("warms the label only once the gathering light reaches it", async ({ mount
127147
expect(cooled).toEqual([0, 0])
128148
})
129149

150+
story("splits a translated label between whole characters", async ({ mount }) => {
151+
// Bengali's two words part at a vowel sign, which draws a dotted circle when it is cut from its consonant.
152+
const timeline = await mount(`${rows}--compaction-and-continuation`, { globals: { locale: "bn" } })
153+
const message = timeline.locator('[data-component="session-compaction-message"]')
154+
155+
await expect(message.locator('[data-slot="session-compaction-divider"]')).toHaveAccessibleName("সংকুচিত হয়েছে")
156+
await expect(message.locator('[data-slot="session-compaction-done"]')).toHaveText(/^\P{M}/u)
157+
})
158+
159+
story("keeps the space where a translated label splits", async ({ mount, page }) => {
160+
// Hindi's two phrases part after a space, which a label split into boxes drops unless it keeps its white space.
161+
const timeline = await mount(`${rows}--compaction-and-continuation`, { globals: { locale: "hi" } })
162+
const label = timeline.locator('[data-slot="session-compaction-label"]')
163+
await expect(timeline.locator('[data-slot="session-compaction-divider"]')).toHaveAccessibleName("संक्षिप्त किया गया")
164+
await page.evaluate(() => document.fonts.ready.then(() => undefined))
165+
166+
// The label's two parts against the same phrase set as one run of text beside it.
167+
const [split, whole] = await label.evaluate((element) => {
168+
const stem = element.firstElementChild
169+
const ending = element.querySelector('[data-slot="session-compaction-done"]')
170+
const copy = element.cloneNode(false)
171+
172+
if (!stem || !ending || !(copy instanceof HTMLElement)) throw new Error("Expected the label's stem and ending")
173+
copy.textContent = element.closest("button")?.getAttribute("aria-label") ?? ""
174+
element.after(copy)
175+
176+
const widths = [
177+
stem.getBoundingClientRect().width + ending.getBoundingClientRect().width,
178+
copy.getBoundingClientRect().width,
179+
]
180+
181+
copy.remove()
182+
183+
return widths
184+
})
185+
186+
expect(whole).toBeGreaterThan(0)
187+
expect(Math.abs(split - whole)).toBeLessThan(1)
188+
})
189+
130190
story("keeps the full record for a manual compaction", async ({ mount }) => {
131191
const timeline = await mount(`${rows}--compaction-manual`)
132192
const message = timeline.locator('[data-component="session-compaction-message"]')

‎packages/session-ui/component-tests/session-timeline-mobile.spec.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,22 @@ story.describe("touch timeline", () => {
9999
await expect(footer).toHaveCSS("opacity", "1")
100100
await expect(footer).toHaveCSS("pointer-events", "auto")
101101
})
102+
103+
story("stops lighting a compaction divider once a tap closes it", async ({ mount }) => {
104+
const timeline = await mount("current-session-timeline-rows--compaction-and-continuation")
105+
const divider = timeline.locator('[data-slot="session-compaction-divider"]')
106+
const label = divider.locator('[data-slot="session-compaction-label"]')
107+
const rest = await label.evaluate((element) => getComputedStyle(element).color)
108+
109+
await divider.tap()
110+
await expect(divider).toHaveAttribute("aria-expanded", "true")
111+
await expect(label).not.toHaveCSS("color", rest)
112+
113+
// The tap leaves :hover on the divider, which must not keep the open colour.
114+
await divider.tap()
115+
await expect(divider).toHaveAttribute("aria-expanded", "false")
116+
await expect(label).toHaveCSS("color", rest)
117+
})
102118
})
103119

104120
story("desktop user message actions still appear on hover and keyboard focus", async ({ mount, page }) => {

‎packages/session-ui/src/components/session-compaction.css‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,11 @@
2222
[data-slot="session-compaction-line"]::before,
2323
[data-slot="session-compaction-light"],
2424
[data-slot="session-compaction-running"],
25+
[data-slot="session-compaction-done"],
2526
[data-slot="session-compaction-glint-stem"],
2627
[data-slot="session-compaction-glint-ending"] {
2728
transition: none;
2829
}
29-
30-
[data-slot="session-compaction-done"] {
31-
transition: color 150ms ease-out;
32-
}
3330
}
3431

3532
[data-slot="session-compaction-divider"] {
@@ -94,6 +91,12 @@
9491
}
9592
}
9693

94+
/* The label is one word, so it changes colour as one. Its parts inherit that colour and never transition their own,
95+
which would trail behind it. */
96+
[data-slot="session-compaction-label"] {
97+
transition: color 150ms ease-out;
98+
}
99+
97100
[data-slot="session-compaction-ending"] > span {
98101
grid-area: 1 / 1;
99102
}
@@ -115,8 +118,7 @@
115118
transition:
116119
opacity 280ms cubic-bezier(0.2, 0.8, 0.2, 1) 80ms,
117120
transform 280ms cubic-bezier(0.2, 0.8, 0.2, 1) 80ms,
118-
filter 280ms cubic-bezier(0.2, 0.8, 0.2, 1) 80ms,
119-
color 150ms ease-out;
121+
filter 280ms cubic-bezier(0.2, 0.8, 0.2, 1) 80ms;
120122
}
121123

122124
/* The label warms only once each light lands on it, then cools before the next one arrives. */
@@ -166,10 +168,16 @@
166168
filter: none;
167169
}
168170

169-
&:not(:disabled):hover [data-slot="session-compaction-done"],
170-
&[aria-expanded="true"] [data-slot="session-compaction-done"] {
171+
&[aria-expanded="true"] [data-slot="session-compaction-label"] {
171172
color: var(--v2-text-text-muted);
172173
}
174+
175+
/* A tap leaves :hover behind, which would keep a closed divider looking open. */
176+
@media (hover: hover) {
177+
&:not(:disabled):hover [data-slot="session-compaction-label"] {
178+
color: var(--v2-text-text-muted);
179+
}
180+
}
173181
}
174182

175183
/* The summary is reference material, so its body sits a step quieter than the conversation around it. */

‎packages/session-ui/src/message/message-content.tsx‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ function QuietCompaction(props: { id: string; created: number; running: boolean;
10911091
</span>
10921092
<span
10931093
data-slot="session-compaction-label"
1094-
class="relative flex shrink-0 whitespace-nowrap text-[13px] font-[440] leading-text-compact tracking-[-0.04px]"
1094+
class="relative flex shrink-0 whitespace-pre text-[13px] font-[440] leading-text-compact tracking-[-0.04px]"
10951095
>
10961096
<span>{label().stem}</span>
10971097
<span data-slot="session-compaction-ending" class="grid justify-items-start">
@@ -1124,10 +1124,14 @@ function QuietCompaction(props: { id: string; created: number; running: boolean;
11241124
)
11251125
}
11261126

1127-
/** Splits Compacting and Compacted at their shared stem, so only the ending changes when the compaction ends. */
1127+
/**
1128+
* Splits Compacting and Compacted at their shared stem, so only the ending changes when the compaction ends. It splits
1129+
* between whole characters as they are read, so a vowel sign stays with its consonant.
1130+
*/
11281131
function splitEnding(running: string, done: string) {
1129-
const chars = [...running]
1130-
const others = [...done]
1132+
const graphemes = new Intl.Segmenter(undefined, { granularity: "grapheme" })
1133+
const chars = Array.from(graphemes.segment(running), (part) => part.segment)
1134+
const others = Array.from(graphemes.segment(done), (part) => part.segment)
11311135
const at = chars.findIndex((char, index) => char !== others[index])
11321136
const stem = chars.slice(0, at === -1 ? chars.length : at).join("")
11331137

‎packages/session-ui/src/timeline-next/compaction.tsx‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ function QuietCompaction(props: { id: string; created: number; running: boolean;
189189
</span>
190190
<span
191191
data-slot="session-compaction-label"
192-
class="relative flex shrink-0 whitespace-nowrap text-[13px] font-[440] leading-text-compact tracking-[-0.04px]"
192+
class="relative flex shrink-0 whitespace-pre text-[13px] font-[440] leading-text-compact tracking-[-0.04px]"
193193
>
194194
<span>{label().stem}</span>
195195
<span data-slot="session-compaction-ending" class="grid justify-items-start">
@@ -221,10 +221,14 @@ function QuietCompaction(props: { id: string; created: number; running: boolean;
221221
)
222222
}
223223

224-
/** Splits Compacting and Compacted at their shared stem, so only the ending changes when the compaction ends. */
224+
/**
225+
* Splits Compacting and Compacted at their shared stem, so only the ending changes when the compaction ends. It splits
226+
* between whole characters as they are read, so a vowel sign stays with its consonant.
227+
*/
225228
function splitEnding(running: string, done: string) {
226-
const chars = [...running]
227-
const others = [...done]
229+
const graphemes = new Intl.Segmenter(undefined, { granularity: "grapheme" })
230+
const chars = Array.from(graphemes.segment(running), (part) => part.segment)
231+
const others = Array.from(graphemes.segment(done), (part) => part.segment)
228232
const at = chars.findIndex((char, index) => char !== others[index])
229233
const stem = chars.slice(0, at === -1 ? chars.length : at).join("")
230234

0 commit comments

Comments
 (0)