Merge pull request #8633 from deepseek-harness/fix/sidebar-scrollbar-fade
fix(web): fade the sidebar scrollbar out 500ms after the pointer leaves
This commit is contained in:
commit
2103f61c01
16 files changed
+286
-142
No files matched your search
@@ -0,0 +1,19 @@
|
||||
# Bilingual-pair consistency record for 2026-11-17-sidebar-scrollbar-fade-in-css.md (docs/i18n/README.md): per heading
|
||||
# section, a hash of its English and Chinese blocks outside code blocks and generated regions.
|
||||
# After editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write .agents/notes/implemented/feature/2026-11-17-sidebar-scrollbar-fade-in-css.md
|
||||
/agent-note-the-sidebar-scrollbar-s-delay-and-fade-live-in-a-css-transition:
|
||||
en: 9b7623eb8949b421
|
||||
zh: d70020274d864676
|
||||
/agent-note-the-sidebar-scrollbar-s-delay-and-fade-live-in-a-css-transition/problem:
|
||||
en: 88d0ec7e97d4d94a
|
||||
zh: 23f3baf3e0a8bdf2
|
||||
/agent-note-the-sidebar-scrollbar-s-delay-and-fade-live-in-a-css-transition/decision:
|
||||
en: 5e1bbaf2825ceac7
|
||||
zh: 7c39baf282e8d63b
|
||||
/agent-note-the-sidebar-scrollbar-s-delay-and-fade-live-in-a-css-transition/alternatives-considered:
|
||||
en: 484736bb70e14bbc
|
||||
zh: 9101a98c7f6be310
|
||||
/agent-note-the-sidebar-scrollbar-s-delay-and-fade-live-in-a-css-transition/consequences:
|
||||
en: 63f48085261affd8
|
||||
zh: 88db30f2ee8a8928
|
||||
@@ -0,0 +1,39 @@
|
||||
# Agent Note: The sidebar scrollbar's delay and fade live in a CSS transition
|
||||
|
||||
Status: implemented
|
||||
|
||||
English | [中文](2026-11-17-sidebar-scrollbar-fade-in-css.zh.md)
|
||||
|
||||
## Problem
|
||||
|
||||
The sidebar draws its scrollbar thumb only while the pointer is over the column. [The pointer-revealed scrollbar note](../../archived/feature/2026-08-04-pointer-revealed-sidebar-scrollbars.md) shipped this with a 2-second JavaScript timer after the leave, and the thumb then vanished in one step. Product review asked for a 500ms hold followed by a visible fade (Issue #7921). That note rejected expressing the delay as a CSS transition; this note reverses that rejection.
|
||||
|
||||
## Decision
|
||||
|
||||
ui-theme registers `--dsh-scrollbar-thumb` and `--dsh-scrollbar-thumb-hover` with `@property` as inherited `<color>` properties whose initial value is `transparent`, so a rebinding of the pair can be transitioned. `SidebarRoot` adds `quietBars` as soon as the pointer is outside the column box and keeps no timer. The `.root.quietBars` rule rebinds both properties to `transparent` with `transition: … 200ms linear 500ms`. The base `.root` rule declares no transition, so a reveal is immediate, and a pointer that returns during the delay removes the class before the colour moves. Under `prefers-reduced-motion: reduce`, the quiet rule sets `transition-duration: 0s`: a zero duration with a non-zero delay still starts a transition, so the thumb holds for 500ms and then switches in one frame.
|
||||
|
||||
The transition runs on the column's custom property, not on a scrollbar pseudo-element. The WebKit thumb's `background: var(--dsh-scrollbar-thumb)` and Firefox's per-element `scrollbar-color` read the property's current animated value at each style update. In Chromium, `apps/web/tests/sidebar-scrollbar.e2e.ts` samples the resolved colour once per animation frame and sees the hold followed by the fade; with the reduced-motion rule removed, the reduced-motion case observes intermediate colours and fails.
|
||||
|
||||
The fade is linear over 200ms, the timing SimpleBar uses. An eased 100ms fade of this pale thumb completes most of its change within a few frames and reads as a cut.
|
||||
|
||||
Inside or outside is decided by the column's box on every `pointerenter` and `pointermove` that reaches the column, because the Settings panel is a fixed-position descendant and the column's menus are React portals: a pointer over them fires no `pointerleave` here while their moves still bubble to the column. The column's own `pointerleave` covers a pointer that leaves the window.
|
||||
|
||||
## Alternatives considered
|
||||
|
||||
**Keep the JavaScript timer and add only a CSS fade.** It needs the same `@property` registration for the fade and keeps a timer, its cancellation, and unmount cleanup in the component. Moving the delay into `transition-delay` removes that state and keeps both timings in one declaration.
|
||||
|
||||
**Leave the properties unregistered.** An unregistered custom property switches in one step, so no transition can hold or fade the colour.
|
||||
|
||||
**Draw an app-owned thumb element and fade its `opacity`.** It gives any fade curve in every engine and costs hit-testing, dragging, wheel, momentum, and hover styling of a replacement scrollbar, which the pointer-revealed scrollbar note already rejected for a cosmetic gain.
|
||||
|
||||
**Hide the bar with `scrollbar-width: none` or `display: none` on `::-webkit-scrollbar`.** It releases the reserved gutter, so revealing the bar would shift every row sideways.
|
||||
|
||||
## Consequences
|
||||
|
||||
The registration is global: every surface that reads the pair now inherits a computed `<color>` instead of the token text, and a value that is not a colour falls back to `transparent` rather than leaving the declaration invalid. Only `.root.quietBars` declares a transition, so other surfaces change neither timing nor colour; the scrollbar geometry golden is unchanged in both palettes.
|
||||
|
||||
The component lost its timer, its document-level listener, and their cleanup. The delay and duration are stated once in the stylesheet, and `scrollbar-quiet-styles.client.spec.ts` pins the exact `transition` value.
|
||||
|
||||
The fade is verified only in Chromium. Safari renders through the same WebKit pseudo-elements; if it does not repaint the thumb during the transition, the thumb holds and then disappears after about 700ms, so the delay still applies without a visible fade.
|
||||
|
||||
A leave during a sidebar collapse or expand hides the thumb at once, because the collapse rule's `transition: width` declaration takes precedence over the quiet rule's.
|
||||
@@ -0,0 +1,39 @@
|
||||
# Agent Note: 侧栏滚动条的延迟与淡出由 CSS 过渡实现
|
||||
|
||||
Status: implemented
|
||||
|
||||
[English](2026-11-17-sidebar-scrollbar-fade-in-css.md) | 中文
|
||||
|
||||
## 问题
|
||||
|
||||
侧栏只在指针位于栏内时绘制滚动条滑块。[指针显示滚动条的 Agent Note](../../archived/feature/2026-08-04-pointer-revealed-sidebar-scrollbars.md) 以离开后 2 秒的 JavaScript 定时器实现了这一行为,之后滑块一步消失。产品评审要求离开后保留 500ms,再明显地淡出(Issue #7921)。那篇 Agent Note 否决了用 CSS 过渡表达延迟;本 Agent Note 推翻这一否决。
|
||||
|
||||
## 决策
|
||||
|
||||
ui-theme 通过 `@property` 把 `--dsh-scrollbar-thumb` 与 `--dsh-scrollbar-thumb-hover` 注册为可继承的 `<color>` 属性,初始值为 `transparent`,因此这组变量的重新绑定可以过渡。`SidebarRoot` 在指针一离开栏的矩形范围时就加上 `quietBars`,不再持有定时器。`.root.quietBars` 规则把两个属性重新绑定为 `transparent`,并带有 `transition: … 200ms linear 500ms`。基础 `.root` 规则不声明过渡,因此显示是立即的;指针在延迟期间返回时,class 在颜色变化前就被移除。在 `prefers-reduced-motion: reduce` 下,隐藏规则设置 `transition-duration: 0s`:时长为零而延迟非零时过渡仍会启动,因此滑块保留 500ms 后在一帧内切换。
|
||||
|
||||
过渡发生在栏元素的自定义属性上,而不是滚动条伪元素上。WebKit 滑块的 `background: var(--dsh-scrollbar-thumb)` 与 Firefox 按元素声明的 `scrollbar-color` 在每次样式更新时读取该属性当前的动画值。在 Chromium 中,`apps/web/tests/sidebar-scrollbar.e2e.ts` 逐个动画帧采样解析后的颜色,能观察到先保留、再淡出;删除减弱动态效果规则后,减弱动态效果用例会观察到中间色并失败。
|
||||
|
||||
淡出为 200ms 线性,与 SimpleBar 的时序相同。这种浅色滑块若用 100ms 缓动淡出,大部分变化在几帧内完成,看起来像直接消失。
|
||||
|
||||
栏内或栏外由栏的矩形范围判定,对到达该栏的每次 `pointerenter` 与 `pointermove` 都会判定。原因是设置面板是固定定位的后代,栏的菜单是 React portal:指针位于其上时这里不会触发 `pointerleave`,而它们的移动事件仍会冒泡到栏。栏自身的 `pointerleave` 处理指针离开窗口的情况。
|
||||
|
||||
## 曾考虑的替代方案
|
||||
|
||||
**保留 JavaScript 定时器,只用 CSS 做淡出。** 淡出同样需要 `@property` 注册,而组件还要保留定时器、取消逻辑与卸载清理。把延迟移入 `transition-delay` 去掉了这些状态,两个时序也集中在一条声明里。
|
||||
|
||||
**不注册这两个属性。** 未注册的自定义属性一步切换,任何过渡都无法保留或淡出颜色。
|
||||
|
||||
**由应用自绘滑块元素并淡出其 `opacity`。** 它在所有引擎上都能实现任意淡出曲线,代价是要为替代滚动条承担命中测试、拖动、滚轮、惯性滚动与 hover 样式,指针显示滚动条的 Agent Note 已因收益只是外观而否决了它。
|
||||
|
||||
**用 `scrollbar-width: none` 或对 `::-webkit-scrollbar` 设置 `display: none` 隐藏滚动条。** 这会释放预留的滚动条空间,显示滚动条时每一行都会横向移动。
|
||||
|
||||
## 后果
|
||||
|
||||
注册是全局的:每个读取这组变量的表面现在继承计算后的 `<color>`,而不是 token 文本;不是颜色的值会回落为 `transparent`,而不是让声明失效。只有 `.root.quietBars` 声明了过渡,因此其他表面的时序与颜色都不变;滚动条几何基准快照在两种配色下均未变化。
|
||||
|
||||
组件去掉了定时器、document 级监听及其清理。延迟与时长只在样式表中声明一次,`scrollbar-quiet-styles.client.spec.ts` 固定了完整的 `transition` 值。
|
||||
|
||||
淡出只在 Chromium 中验证过。Safari 通过同样的 WebKit 伪元素绘制;如果它在过渡期间不重绘滑块,滑块会保留并在约 700ms 后消失,延迟依然生效,只是没有可见的淡出。
|
||||
|
||||
在侧栏折叠或展开过程中离开时,滑块会立即隐藏,因为折叠规则的 `transition: width` 声明优先于隐藏规则的声明。
|
||||
@@ -161,8 +161,8 @@ interface PaletteMetrics {
|
||||
*/
|
||||
async function measurePalette(page: Page): Promise<PaletteMetrics> {
|
||||
await pointAt(page, 'away')
|
||||
// Poll rather than sleep the linger out: the wait is the column's, and a
|
||||
// fixed sleep would either race it or pad every palette.
|
||||
// Poll rather than sleep out the column's delay and fade: a fixed sleep
|
||||
// would either race them or pad every palette.
|
||||
await expect.poll(async () => resolveThumb(page), { timeout: 10_000 }).toBe(NO_THUMB)
|
||||
const quietThumb = await resolveThumb(page)
|
||||
await pointAt(page, 'list')
|
||||
@@ -234,6 +234,50 @@ function resolveThumb(page: Page): Promise<string> {
|
||||
/** Fully transparent, which is how the quiet column spells "no thumb". */
|
||||
const NO_THUMB = 'rgba(0, 0, 0, 0)'
|
||||
|
||||
/** The quiet rule's transition delay, less one frame of sampling slack. */
|
||||
const MIN_QUIET_DELAY_MS = 450
|
||||
|
||||
/** What {@link leaveAndSampleThumb} observed between the leave and the quiet thumb. */
|
||||
interface LeaveSamples {
|
||||
/** Distinct thumb colours seen, in order of first appearance. */
|
||||
colours: string[]
|
||||
/** Milliseconds from just before the leave until the first transparent frame. */
|
||||
elapsedMs: number
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the pointer away and read the list's thumb once per animation frame
|
||||
* until it is transparent. The sampler starts in the page before the move, so
|
||||
* the elapsed time is a lower bound on the hold whatever the round-trip
|
||||
* latency of the harness is.
|
||||
* @param page - the page under test.
|
||||
* @returns the colours seen and how long the thumb took to go transparent.
|
||||
*/
|
||||
async function leaveAndSampleThumb(page: Page): Promise<LeaveSamples> {
|
||||
const sampled = page.evaluate(async (none) => {
|
||||
const list = document.querySelector<HTMLElement>('[data-sidebar-list-area]')
|
||||
if (list === null) throw new Error('sidebar session list not in the DOM')
|
||||
const probe = document.createElement('span')
|
||||
probe.style.color = 'var(--dsh-scrollbar-thumb)'
|
||||
list.append(probe)
|
||||
const start = performance.now()
|
||||
const colours: string[] = []
|
||||
try {
|
||||
for (;;) {
|
||||
const value = getComputedStyle(probe).color
|
||||
if (!colours.includes(value)) colours.push(value)
|
||||
if (value === none) return { colours, elapsedMs: performance.now() - start }
|
||||
if (performance.now() - start > 10_000) throw new Error(`thumb never went quiet: ${colours.join(' → ')}`)
|
||||
await new Promise(resolve => requestAnimationFrame(resolve))
|
||||
}
|
||||
} finally {
|
||||
probe.remove()
|
||||
}
|
||||
}, NO_THUMB)
|
||||
await pointAt(page, 'away')
|
||||
return sampled
|
||||
}
|
||||
|
||||
/**
|
||||
* Park the pointer over the session list or outside the sidebar entirely. The
|
||||
* column reveals its scrollbars from real pointer movement, so a scenario that
|
||||
@@ -385,16 +429,15 @@ describe('web e2e: sidebar session list scrollbar (reserved gutter / themed thum
|
||||
expect(tripwire.pageErrors).toEqual([])
|
||||
}, 60_000)
|
||||
|
||||
it('draws no thumb until the pointer is over the column, and lingers on the way out', async () => {
|
||||
it('draws no thumb until the pointer is over the column, and fades it out shortly after the pointer leaves', async () => {
|
||||
onTestFailed(() => saveFailureShot(page, 'web-e2e-sidebar-scrollbar-pointer'))
|
||||
const revealed = await resolveThumb(page)
|
||||
expect(revealed).not.toBe(NO_THUMB)
|
||||
await pointAt(page, 'away')
|
||||
// The linger, measured as a state rather than a duration: the thumb is
|
||||
// still drawn on the leave itself, and gone once the window has passed. A
|
||||
// tighter timing assertion would pin the wall clock of a CI machine.
|
||||
expect(await resolveThumb(page)).toBe(revealed)
|
||||
await expect.poll(async () => resolveThumb(page), { timeout: 10_000 }).toBe(NO_THUMB)
|
||||
// The delay is checked as a lower bound measured in the page: a slow
|
||||
// harness only lengthens it, so no upper bound pins a CI wall clock.
|
||||
const leave = await leaveAndSampleThumb(page)
|
||||
expect(leave.colours[0]).toBe(revealed)
|
||||
expect(leave.elapsedMs).toBeGreaterThanOrEqual(MIN_QUIET_DELAY_MS)
|
||||
// The reservation is unconditional, so nothing moved while the bar was
|
||||
// hidden — this is what buys `transparent` over hiding the bar itself.
|
||||
const quiet = await measureList(page)
|
||||
@@ -413,6 +456,27 @@ describe('web e2e: sidebar session list scrollbar (reserved gutter / themed thum
|
||||
expect(tripwire.pageErrors).toEqual([])
|
||||
}, 60_000)
|
||||
|
||||
it('keeps the delay and drops the fade under reduced motion', async () => {
|
||||
onTestFailed(() => saveFailureShot(page, 'web-e2e-sidebar-scrollbar-reduced-motion'))
|
||||
await page.emulateMedia({ reducedMotion: 'reduce' })
|
||||
try {
|
||||
await pointAt(page, 'list')
|
||||
await expect.poll(async () => resolveThumb(page), { timeout: 10_000 }).not.toBe(NO_THUMB)
|
||||
const revealed = await resolveThumb(page)
|
||||
// A zero duration with a non-zero delay still starts a transition, so
|
||||
// the thumb holds its colour through the delay and then switches in one
|
||||
// frame: no intermediate colour may appear.
|
||||
const leave = await leaveAndSampleThumb(page)
|
||||
expect(leave.colours).toEqual([revealed, NO_THUMB])
|
||||
expect(leave.elapsedMs).toBeGreaterThanOrEqual(MIN_QUIET_DELAY_MS)
|
||||
} finally {
|
||||
await page.emulateMedia({ reducedMotion: 'no-preference' })
|
||||
await pointAt(page, 'list')
|
||||
await expect.poll(async () => resolveThumb(page), { timeout: 10_000 }).not.toBe(NO_THUMB)
|
||||
}
|
||||
expect(tripwire.pageErrors).toEqual([])
|
||||
}, 60_000)
|
||||
|
||||
it('removes both scroll ranges without moving row edges when grouped content fits', async () => {
|
||||
onTestFailed(() => saveFailureShot(page, 'web-e2e-sidebar-scrollbar-stable-inset'))
|
||||
const viewport = page.locator('[data-sidebar-list-area]')
|
||||
|
||||
@@ -30,8 +30,8 @@
|
||||
en: 28e3639ed58492e0
|
||||
zh: 4896acd767287c8a
|
||||
/deepseek-ai-dsh-client-ui-sidebar/use-this-package/scrollbars:
|
||||
en: 9e7b31acee759f2b
|
||||
zh: 3a6beb63b23d26ae
|
||||
en: dd59917acefeab78
|
||||
zh: 28d70c963795c0a0
|
||||
/deepseek-ai-dsh-client-ui-sidebar/use-this-package/click-analytics:
|
||||
en: 3e84ffdf6c7c1731
|
||||
zh: 3f7b19cac6d6674f
|
||||
|
||||
@@ -61,7 +61,7 @@ Under `html[data-platform='darwin']` (set only by the desktop preload) the expan
|
||||
|
||||
### Scrollbars
|
||||
|
||||
Scrollbars in the column are a pointer affordance: the shell rebinds the scrollbar indirection to `transparent` whenever the pointer is outside the column and keeps the thumb drawn for 2s after the pointer leaves, so a list nobody is pointing at carries no bar. The reservation that keeps rows from moving belongs to the scrolling region (ui-workspace), so revealing a thumb never reflows.
|
||||
Scrollbars in the column are a pointer affordance: the shell rebinds the scrollbar indirection to `transparent` whenever the pointer is outside the column, so a list nobody is pointing at carries no bar. After the pointer leaves, the thumb stays drawn for 500ms and then fades out linearly over 200ms; a pointer that returns before the fade ends redraws it at once, and reduced motion keeps the delay without the fade. Outside is decided by the column's box for every pointer move that reaches the column, so a pointer over the fixed-position Settings panel or a portalled menu outside the box also counts as outside. The reservation that keeps rows from moving belongs to the scrolling region (ui-workspace), so revealing a thumb never reflows.
|
||||
|
||||
### Click analytics
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ root 作用域的 `sidebar.session.action` 是包裹新建会话行内容的 HOC
|
||||
|
||||
### 滚动条
|
||||
|
||||
栏内的滚动条是一种指针可供性:只要指针不在栏内,外壳就把滚动条间接层重新绑定为 `transparent`;指针离开后滑块再保留 2 秒,因此没人指向的列表不会带着滚动条。避免行位移的空间预留属于滚动区域本身(ui-workspace),所以显示滑块不会引起重排。
|
||||
栏内的滚动条是一种指针可供性:只要指针不在栏内,外壳就把滚动条间接层重新绑定为 `transparent`,因此没人指向的列表不会带着滚动条。指针离开后,滑块先保留 500ms,再在 200ms 内线性淡出;淡出结束前指针返回会立即重新显示滑块,减弱动态效果时保留延迟但不淡出。是否在栏内按栏的矩形范围判定,对每次到达该栏的指针移动都会判定,因此指针位于固定定位的设置面板或栏外的 portal 菜单上时,同样算作在栏外。避免行位移的空间预留属于滚动区域本身(ui-workspace),所以显示滑块不会引起重排。
|
||||
|
||||
### 点击埋点
|
||||
|
||||
|
||||
@@ -124,16 +124,25 @@
|
||||
}
|
||||
|
||||
/* Scrollbars in the column are a pointer affordance: the shell adds this
|
||||
class whenever the pointer is not inside (SidebarRoot.tsx owns the linger),
|
||||
class whenever the pointer is not inside (SidebarRoot.tsx tracks it),
|
||||
and rebinding ui-theme's indirection pair to `transparent` takes the thumb
|
||||
out of every scroll region nested under it — the workspace browser's
|
||||
session list. `transparent` rather than `display: none` on the bar:
|
||||
the reservation (`scrollbar-gutter: stable` on the list) stays in force, so
|
||||
revealing the thumb never reflows a row. Rebinding contract and the two
|
||||
rendering paths it reaches: ui-theme's README. */
|
||||
rendering paths it reaches: ui-theme's README.
|
||||
The thumb stays drawn for 500ms after the pointer leaves, then fades out
|
||||
linearly over 200ms; an eased or shorter fade of this pale thumb completes
|
||||
most of its change in a few frames and reads as a cut. Only the quiet state
|
||||
carries the transition, so a reveal is immediate and a pointer that returns
|
||||
during the delay sees no change. The collapse rule's `transition: width`
|
||||
outranks this one, so a leave during collapse or expand hides at once. */
|
||||
.root.quietBars {
|
||||
--dsh-scrollbar-thumb: transparent;
|
||||
--dsh-scrollbar-thumb-hover: transparent;
|
||||
transition:
|
||||
--dsh-scrollbar-thumb 200ms linear 500ms,
|
||||
--dsh-scrollbar-thumb-hover 200ms linear 500ms;
|
||||
}
|
||||
|
||||
/* Collapse phase 1: the whole frozen-width content fades out in place over
|
||||
@@ -841,4 +850,9 @@
|
||||
transition: none;
|
||||
animation: none;
|
||||
}
|
||||
|
||||
/* The delay is not motion: keep it and drop only the fade. */
|
||||
.root.quietBars {
|
||||
transition-duration: 0s;
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
* pointing at carries no bar.
|
||||
*/
|
||||
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'
|
||||
import type { PointerEvent as ReactPointerEvent } from 'react'
|
||||
import clsx from 'clsx'
|
||||
import {
|
||||
FishLogo, IconAppsAddOutlineRegular, IconNewChatOutlineMedium, IconNewChatOutlineRegular,
|
||||
@@ -37,14 +38,6 @@ import css from './SidebarRoot.module.css'
|
||||
/** Wide-content unmount delay; matches the 150ms wide-content fade-out. */
|
||||
const COLLAPSE_SETTLE_MS = 150
|
||||
|
||||
/**
|
||||
* How long the column's scrollbars stay drawn after the pointer leaves it.
|
||||
* The bar is a pointer affordance here, and hiding it on the leave event
|
||||
* itself makes it blink out while the pointer is only crossing the column's
|
||||
* edge — on the way to the conversation, or around a portalled menu.
|
||||
*/
|
||||
const SCROLLBAR_LINGER_MS = 2000
|
||||
|
||||
/** Format complete-build metadata for the local brand badge. */
|
||||
function localBuildVersion(): string | undefined {
|
||||
const version = process.env.DSH_CLIENT_VERSION
|
||||
@@ -210,10 +203,9 @@ export function SidebarRoot({
|
||||
const animateRail = useRef(!collapsed)
|
||||
if (drawer || !collapsed) animateRail.current = !collapsed
|
||||
|
||||
// Scrollbars in the column follow the pointer (.quietBars rebinds them
|
||||
// away): drawn while it is inside, and for SCROLLBAR_LINGER_MS after it
|
||||
// leaves. A pointer that returns within that window cancels the pending
|
||||
// hide rather than restarting from a hidden bar.
|
||||
// Scrollbars in the column follow the pointer: .quietBars rebinds them away
|
||||
// whenever the pointer is outside, and its stylesheet owns the delay and
|
||||
// fade, so a pointer that returns before the fade starts sees no change.
|
||||
const column = useRef<HTMLDivElement>(null)
|
||||
const sidebarFocus = useRef<Element | null>(null)
|
||||
useModalLayer(column, drawer && !collapsed, toggleSidebar)
|
||||
@@ -228,42 +220,18 @@ export function SidebarRoot({
|
||||
if (opener != null && !isBehindModal(opener)) focusWithoutRing(opener, { preventScroll: true })
|
||||
}, [drawer, collapsed])
|
||||
const [pointerInside, setPointerInside] = useState(false)
|
||||
const lingerTimer = useRef<number | undefined>(undefined)
|
||||
const armLinger = (): void => {
|
||||
if (lingerTimer.current !== undefined) return
|
||||
lingerTimer.current = window.setTimeout(() => {
|
||||
lingerTimer.current = undefined
|
||||
setPointerInside(false)
|
||||
}, SCROLLBAR_LINGER_MS)
|
||||
}
|
||||
const cancelLinger = (): void => {
|
||||
window.clearTimeout(lingerTimer.current)
|
||||
lingerTimer.current = undefined
|
||||
}
|
||||
// Leaving is decided by the column's BOX, not by DOM containment, and only
|
||||
// while the bars are drawn. ui-settings renders its full-viewport panel as a
|
||||
// fixed-position DESCENDANT of this column, so a pointer moved onto that
|
||||
// panel — or onto the conversation once it closes — fires no `pointerleave`
|
||||
// here, and the bars would stay drawn over a column nobody is pointing at.
|
||||
// The element's own leave stays as the one signal geometry cannot give: a
|
||||
// Inside is decided by the column's BOX, not by DOM containment, for every
|
||||
// pointer move that reaches the column. ui-settings renders its
|
||||
// full-viewport panel as a fixed-position DESCENDANT of this column, and the
|
||||
// column's menus and tooltips are React portals, so a pointer over them
|
||||
// fires no `pointerleave` here while their moves still bubble to it. The
|
||||
// element's own leave stays as the one signal geometry cannot give: a
|
||||
// pointer that leaves the window emits no further moves.
|
||||
useEffect(() => {
|
||||
if (!pointerInside) return
|
||||
const onMove = (event: PointerEvent): void => {
|
||||
const rect = column.current?.getBoundingClientRect()
|
||||
/* v8 ignore next -- the listener only exists while the column is mounted and revealed. */
|
||||
if (rect === undefined) return
|
||||
const inside = event.clientX >= rect.left && event.clientX < rect.right
|
||||
&& event.clientY >= rect.top && event.clientY < rect.bottom
|
||||
if (inside) cancelLinger()
|
||||
else armLinger()
|
||||
}
|
||||
document.addEventListener('pointermove', onMove)
|
||||
return () => {
|
||||
document.removeEventListener('pointermove', onMove)
|
||||
cancelLinger()
|
||||
}
|
||||
}, [pointerInside])
|
||||
const trackPointer = (event: ReactPointerEvent<HTMLDivElement>): void => {
|
||||
const rect = event.currentTarget.getBoundingClientRect()
|
||||
setPointerInside(event.clientX >= rect.left && event.clientX < rect.right
|
||||
&& event.clientY >= rect.top && event.clientY < rect.bottom)
|
||||
}
|
||||
|
||||
const buildVersion = localBuildVersion()
|
||||
// The local-build fallbacks copy the badge text; the brand button below
|
||||
@@ -318,11 +286,9 @@ export function SidebarRoot({
|
||||
!drawer && collapsed && wide && css.fading, !pointerInside && css.quietBars,
|
||||
)}
|
||||
style={wide ? { width: !drawer && collapsed ? lastWideWidth.current : width } : undefined}
|
||||
onPointerEnter={() => {
|
||||
cancelLinger()
|
||||
setPointerInside(true)
|
||||
}}
|
||||
onPointerLeave={() => { armLinger() }}
|
||||
onPointerEnter={trackPointer}
|
||||
onPointerMove={trackPointer}
|
||||
onPointerLeave={() => { setPointerInside(false) }}
|
||||
>
|
||||
{/* macOS hiddenInset titlebar: the strip shares the row with the
|
||||
traffic lights and keeps the toggle at the sidebar's top-right. */}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { contextMenuHook } from '@deepseek-ai/dsh-client-test-runtime'
|
||||
*/
|
||||
import type { GlobalStandardProps } from '@deepseek-ai/dsh-client-ui-slots'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { act, cleanup, fireEvent, render } from '@testing-library/react'
|
||||
import { cleanup, fireEvent, render } from '@testing-library/react'
|
||||
import { allowAllAccess } from '@deepseek-ai/dsh-client-test-runtime'
|
||||
import type { SidebarRootComponentProps, SidebarSectionOwnerProps } from '../src/client/contract/slots.ts'
|
||||
import { SidebarRoot } from '../src/client/SidebarRoot.tsx'
|
||||
@@ -31,7 +31,6 @@ const useSessionStatus: SidebarRootComponentProps['useSessionStatus'] = selector
|
||||
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -79,96 +78,50 @@ function mountColumn(): { column: HTMLElement; quiet: () => boolean } {
|
||||
*/
|
||||
function movePointer(column: HTMLElement, direction: 'in' | 'out'): void {
|
||||
const outside = document.body
|
||||
if (direction === 'in') fireEvent.pointerOver(column, { relatedTarget: outside })
|
||||
else fireEvent.pointerOut(column, { relatedTarget: outside })
|
||||
if (direction === 'in') fireEvent.pointerOver(column, { relatedTarget: outside, clientX: 40, clientY: 300 })
|
||||
else fireEvent.pointerOut(column, { relatedTarget: outside, clientX: COLUMN_WIDTH + 40, clientY: 300 })
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the pointer over the document, as a pointer crossing a fixed overlay
|
||||
* that is a DOM descendant of the column does.
|
||||
* Move the pointer over a descendant of the column, as a pointer crossing a
|
||||
* fixed-position overlay rendered inside it does: the move bubbles to the
|
||||
* column without any leave.
|
||||
* @param target - the descendant the pointer is over.
|
||||
* @param x - client x coordinate.
|
||||
* @param y - client y coordinate.
|
||||
*/
|
||||
function movePointerOverDocument(x: number, y: number): void {
|
||||
fireEvent.pointerMove(document, { clientX: x, clientY: y })
|
||||
function movePointerOver(target: Element, x: number, y: number): void {
|
||||
fireEvent.pointerMove(target, { clientX: x, clientY: y })
|
||||
}
|
||||
|
||||
describe('SidebarRoot pointer-revealed scrollbars', () => {
|
||||
it('draws them only while the pointer is inside, and lingers on the way out', () => {
|
||||
vi.useFakeTimers()
|
||||
it('draws them only while the pointer is inside', () => {
|
||||
const { column, quiet } = mountColumn()
|
||||
// At rest — the pointer has never been over the column — the bars are off.
|
||||
expect(quiet()).toBe(true)
|
||||
movePointer(column, 'in')
|
||||
expect(quiet()).toBe(false)
|
||||
// The quiet state applies on the leave itself; its stylesheet owns the
|
||||
// delay and fade (scrollbar-quiet-styles.client.spec.ts).
|
||||
movePointer(column, 'out')
|
||||
// The linger: still drawn just before the window closes, gone just after.
|
||||
act(() => { vi.advanceTimersByTime(1999) })
|
||||
expect(quiet()).toBe(false)
|
||||
act(() => { vi.advanceTimersByTime(1) })
|
||||
expect(quiet()).toBe(true)
|
||||
})
|
||||
|
||||
it('cancels a pending hide when the pointer comes back', () => {
|
||||
vi.useFakeTimers()
|
||||
const { column, quiet } = mountColumn()
|
||||
movePointer(column, 'in')
|
||||
movePointer(column, 'out')
|
||||
act(() => { vi.advanceTimersByTime(1000) })
|
||||
movePointer(column, 'in')
|
||||
// The first leave's timer would fire here; a cancelled one leaves the bars
|
||||
// drawn, which is what keeps a pointer skirting the edge from blinking them.
|
||||
act(() => { vi.advanceTimersByTime(5000) })
|
||||
expect(quiet()).toBe(false)
|
||||
})
|
||||
|
||||
it('hides when the pointer moves outside the column box without leaving its subtree', () => {
|
||||
it('follows the column box while the pointer is over a descendant overlay', () => {
|
||||
// ui-settings renders its full-viewport panel as a fixed-position
|
||||
// DESCENDANT of the column, so DOM containment reports the pointer as
|
||||
// still inside while it is visually somewhere else entirely.
|
||||
vi.useFakeTimers()
|
||||
const { column, quiet } = mountColumn()
|
||||
const overlay = column.querySelector('[data-testid="region"]')
|
||||
if (overlay === null) throw new Error('region not rendered')
|
||||
movePointer(column, 'in')
|
||||
expect(quiet()).toBe(false)
|
||||
movePointerOverDocument(COLUMN_WIDTH + 400, 300)
|
||||
act(() => { vi.advanceTimersByTime(2000) })
|
||||
movePointerOver(overlay, COLUMN_WIDTH + 400, 300)
|
||||
expect(quiet()).toBe(true)
|
||||
})
|
||||
|
||||
it('does not restart the window when the pointer keeps moving outside', () => {
|
||||
vi.useFakeTimers()
|
||||
const { column, quiet } = mountColumn()
|
||||
movePointer(column, 'in')
|
||||
movePointer(column, 'out')
|
||||
act(() => { vi.advanceTimersByTime(1500) })
|
||||
// A pending hide is left alone rather than re-armed: otherwise a pointer
|
||||
// resting outside the column would keep pushing the bars' disappearance
|
||||
// out, one move at a time.
|
||||
movePointerOverDocument(COLUMN_WIDTH + 400, 300)
|
||||
act(() => { vi.advanceTimersByTime(600) })
|
||||
expect(quiet()).toBe(true)
|
||||
})
|
||||
|
||||
it('keeps them drawn while the pointer moves inside the column box', () => {
|
||||
vi.useFakeTimers()
|
||||
const { column, quiet } = mountColumn()
|
||||
movePointer(column, 'in')
|
||||
movePointer(column, 'out')
|
||||
// A move landing back inside the box cancels the pending hide, the same
|
||||
// way re-entering the element does.
|
||||
movePointerOverDocument(COLUMN_WIDTH - 10, 300)
|
||||
act(() => { vi.advanceTimersByTime(5000) })
|
||||
movePointerOver(overlay, COLUMN_WIDTH - 10, COLUMN_HEIGHT - 10)
|
||||
expect(quiet()).toBe(false)
|
||||
})
|
||||
|
||||
it('drops the pending hide when the column unmounts', () => {
|
||||
vi.useFakeTimers()
|
||||
const { column } = mountColumn()
|
||||
movePointer(column, 'in')
|
||||
movePointer(column, 'out')
|
||||
cleanup()
|
||||
// A timer surviving the unmount would call setState on a dead component.
|
||||
expect(() => { vi.advanceTimersByTime(5000) }).not.toThrow()
|
||||
expect(vi.getTimerCount()).toBe(0)
|
||||
movePointerOver(overlay, 10, COLUMN_HEIGHT + 10)
|
||||
expect(quiet()).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -12,19 +12,43 @@ const css = readFileSync(fileURLToPath(new URL('../src/client/SidebarRoot.module
|
||||
/** Declarations only: the sheet's prose names the properties it explains. */
|
||||
const declarationText = css.replace(/\/\*[\s\S]*?\*\//g, ' ')
|
||||
|
||||
/**
|
||||
* The quiet rule's declarations, trimmed.
|
||||
* @returns each declaration of `.root.quietBars` as written.
|
||||
*/
|
||||
function quietDeclarations(): string[] {
|
||||
const rule = /\.root\.quietBars\s*\{([^{}]*)\}/.exec(declarationText)
|
||||
expect(rule).not.toBeNull()
|
||||
return (rule![1] ?? '').split(';').map(part => part.trim()).filter(Boolean)
|
||||
}
|
||||
|
||||
describe('SidebarRoot.module.css quiet column', () => {
|
||||
it('rebinds the ui-theme indirection pair to transparent', () => {
|
||||
// The pair, not the resting thumb alone: rebinding one leaves the other
|
||||
// painting its base-surface colour the moment the pointer reaches the bar.
|
||||
const rule = /\.root\.quietBars\s*\{([^{}]*)\}/.exec(declarationText)
|
||||
expect(rule).not.toBeNull()
|
||||
const declarations = (rule![1] ?? '').split(';').map(part => part.trim()).filter(Boolean).sort()
|
||||
const declarations = quietDeclarations().filter(part => !part.startsWith('transition')).sort()
|
||||
expect(declarations).toEqual([
|
||||
'--dsh-scrollbar-thumb-hover: transparent',
|
||||
'--dsh-scrollbar-thumb: transparent',
|
||||
].sort())
|
||||
})
|
||||
|
||||
it('fades both halves of the pair out after a delay, and only on the way to quiet', () => {
|
||||
const transition = quietDeclarations().find(part => part.startsWith('transition:'))
|
||||
expect(transition?.replace(/\s+/g, ' ')).toBe(
|
||||
'transition: --dsh-scrollbar-thumb 200ms linear 500ms, --dsh-scrollbar-thumb-hover 200ms linear 500ms',
|
||||
)
|
||||
// A reveal has no transition: the base rule declares none.
|
||||
const base = /(?:^|\})\s*\.root\s*\{([^{}]*)\}/.exec(declarationText)
|
||||
expect(base).not.toBeNull()
|
||||
expect(base![1]).not.toMatch(/transition/)
|
||||
})
|
||||
|
||||
it('keeps the delay and drops the fade under reduced motion', () => {
|
||||
const reduced = /@media \(prefers-reduced-motion: reduce\)\s*\{([\s\S]*)\}\s*$/.exec(declarationText)
|
||||
expect(reduced?.[1]).toMatch(/\.root\.quietBars\s*\{\s*transition-duration:\s*0s;\s*\}/)
|
||||
})
|
||||
|
||||
it('leaves the gutter reservation to the scrolling region', () => {
|
||||
// Hiding the thumb must not move a row: the reservation lives on the list
|
||||
// (ui-workspace), so the column states colour only.
|
||||
|
||||
@@ -36,8 +36,8 @@
|
||||
en: 148903d8cd6580f5
|
||||
zh: 7ff2ff90954798b8
|
||||
/deepseek-ai-dsh-client-ui-theme/understand-the-implementation/scrollbar-rebinding:
|
||||
en: bf76e7c34a331595
|
||||
zh: 5accd0260ef7c61e
|
||||
en: 3448f0857e398018
|
||||
zh: 0b5078286134b8e9
|
||||
/deepseek-ai-dsh-client-ui-theme/understand-the-implementation/preference-persistence:
|
||||
en: b1f0b0bce5e53bae
|
||||
zh: 26ded298f85834ae
|
||||
|
||||
@@ -95,7 +95,7 @@ The `--dsw-alias-turn-trigger-*` tokens provide separate resting and hover backg
|
||||
|
||||
### Scrollbar rebinding
|
||||
|
||||
`scrollbar.css` binds `--dsh-scrollbar-thumb` and `--dsh-scrollbar-thumb-hover` on `body` to the l1 base-surface tokens; an elevated surface (menu, popover, dialog) rebinds them to the l2 tokens on its own container, and the pair's other legal target is `transparent` (ui-sidebar rebinds its column that way while the pointer is elsewhere). WebKit-based browsers use a 5px default `--dsh-scrollbar-width` and also read `--dsh-scrollbar-thumb-border` and `--dsh-scrollbar-track-margin`; a scroll surface may rebind them to keep a wide draggable rail around a narrower visible thumb or to inset the track from rounded ends. The two rendering paths are mutually exclusive by construction: Firefox takes the standard thin scrollbar inside `@supports not selector(::-webkit-scrollbar)`, and WebKit-based engines take the pseudo-elements, so geometry and hover customization apply only through the pseudo-element path.
|
||||
`scrollbar.css` binds `--dsh-scrollbar-thumb` and `--dsh-scrollbar-thumb-hover` on `body` to the l1 base-surface tokens; an elevated surface (menu, popover, dialog) rebinds them to the l2 tokens on its own container, and the pair's other legal target is `transparent` (ui-sidebar rebinds its column that way while the pointer is elsewhere). Both are registered with `@property` as inherited `<color>` properties whose initial value is `transparent`, so a surface can transition a rebinding; ui-sidebar fades its thumb out that way. WebKit-based browsers use a 5px default `--dsh-scrollbar-width` and also read `--dsh-scrollbar-thumb-border` and `--dsh-scrollbar-track-margin`; a scroll surface may rebind them to keep a wide draggable rail around a narrower visible thumb or to inset the track from rounded ends. The two rendering paths are mutually exclusive by construction: Firefox takes the standard thin scrollbar inside `@supports not selector(::-webkit-scrollbar)`, and WebKit-based engines take the pseudo-elements, so geometry and hover customization apply only through the pseudo-element path.
|
||||
|
||||
### Preference persistence
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ Desktop 的固定快捷键 `Cmd`/`Ctrl` + `+`(或 `=`)和 `Cmd`/`Ctrl` + `-`
|
||||
|
||||
### 滚动条重新绑定
|
||||
|
||||
`scrollbar.css` 在 `body` 上把 `--dsh-scrollbar-thumb` 与 `--dsh-scrollbar-thumb-hover` 绑定到 l1 基础表面 token;高层级表面(菜单、浮层、对话框)在自己的容器上把它们重新绑定为 l2 token;这组变量的另一个合法目标是 `transparent`(ui-sidebar 在指针不在栏内时就这样重新绑定自己的列)。WebKit 系浏览器默认使用 5px 的 `--dsh-scrollbar-width`,并读取 `--dsh-scrollbar-thumb-border` 与 `--dsh-scrollbar-track-margin`;滚动表面可重新绑定它们,在较窄的可见滑块外保留较宽的拖动区域,或让轨道避开圆角两端。两条渲染路径在构造上互斥:Firefox 走 `@supports not selector(::-webkit-scrollbar)` 内的标准细滚动条,WebKit 系引擎走伪元素,因此几何与 hover 定制只经由伪元素路径生效。
|
||||
`scrollbar.css` 在 `body` 上把 `--dsh-scrollbar-thumb` 与 `--dsh-scrollbar-thumb-hover` 绑定到 l1 基础表面 token;高层级表面(菜单、浮层、对话框)在自己的容器上把它们重新绑定为 l2 token;这组变量的另一个合法目标是 `transparent`(ui-sidebar 在指针不在栏内时就这样重新绑定自己的列)。两者都通过 `@property` 注册为可继承的 `<color>` 属性,初始值为 `transparent`,因此表面可以为重新绑定添加过渡;ui-sidebar 就以这种方式让滑块淡出。WebKit 系浏览器默认使用 5px 的 `--dsh-scrollbar-width`,并读取 `--dsh-scrollbar-thumb-border` 与 `--dsh-scrollbar-track-margin`;滚动表面可重新绑定它们,在较窄的可见滑块外保留较宽的拖动区域,或让轨道避开圆角两端。两条渲染路径在构造上互斥:Firefox 走 `@supports not selector(::-webkit-scrollbar)` 内的标准细滚动条,WebKit 系引擎走伪元素,因此几何与 hover 定制只经由伪元素路径生效。
|
||||
|
||||
### 偏好持久化
|
||||
|
||||
|
||||
@@ -5,14 +5,29 @@
|
||||
* The rules sit on `body`, not `html`: design-platform.css declares the
|
||||
* --dsw-alias-* tokens on `body` (and the dark overrides on
|
||||
* `body[data-ds-dark-theme]`), and custom properties only inherit downward,
|
||||
* so an `html` rule resolves them to the guaranteed-invalid value and
|
||||
* `scrollbar-color` falls back to `auto`.
|
||||
* so an `html` rule resolves them to the guaranteed-invalid value and the
|
||||
* registered indirection below to its `transparent` initial value, hiding
|
||||
* every thumb.
|
||||
*
|
||||
* Surfaces pick their elevation by rebinding --dsh-scrollbar-thumb{,-hover}:
|
||||
* the l1 pair here is the base-surface default, and an elevated surface
|
||||
* (menu, popover, dialog) rebinds to the l2 pair on its own container. A
|
||||
* scroll container may also rebind the three geometry variables below. */
|
||||
|
||||
/* Registered as inherited colours so a surface can transition its rebinding;
|
||||
an unregistered custom property switches in one step. */
|
||||
@property --dsh-scrollbar-thumb {
|
||||
syntax: '<color>';
|
||||
inherits: true;
|
||||
initial-value: transparent;
|
||||
}
|
||||
|
||||
@property --dsh-scrollbar-thumb-hover {
|
||||
syntax: '<color>';
|
||||
inherits: true;
|
||||
initial-value: transparent;
|
||||
}
|
||||
|
||||
body {
|
||||
--dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l1);
|
||||
--dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l1);
|
||||
|
||||
@@ -273,6 +273,17 @@ describe('scrollbar.css base-surface binding', () => {
|
||||
expect(indirection).toBe(`${INDIRECTION_PREFIX}thumb`)
|
||||
expect(varReferences(declaration(scrollbarRules, 'background', '::-webkit-scrollbar-thumb')!)).toEqual([indirection])
|
||||
})
|
||||
|
||||
it('registers the thumb pair as inherited colours so a rebinding can transition', () => {
|
||||
const comments = /\/\*[\s\S]*?\*\//g
|
||||
const registered = [...scrollbarCss.replace(comments, ' ').matchAll(/@property\s+(--[\w-]+)\s*\{([^{}]*)\}/g)]
|
||||
.map(([, name, body]) => [name, body!.split(';').map(part => part.trim()).filter(Boolean).sort()])
|
||||
const descriptors = ['inherits: true', 'initial-value: transparent', "syntax: '<color>'"]
|
||||
expect(registered).toEqual([
|
||||
[`${INDIRECTION_PREFIX}thumb`, descriptors],
|
||||
[`${INDIRECTION_PREFIX}thumb-hover`, descriptors],
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('scrollbar.css geometry variables', () => {
|
||||
|
||||
Reference in new issue
Block a user