From be7539937f4603093c00ff661bb23f1f038a4906 Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Fri, 23 Oct 2026 20:04:50 -0700 Subject: [PATCH] fix(app): fade sidebar contents only near closed and show hover actions instantly (#58577) --- packages/app/src/shell/panel-motion.test.ts | 14 +++++-- packages/app/src/shell/panel-motion.ts | 39 ++++++++++++++----- .../app/test-browser/panel-motion.test.ts | 21 +++++++++- .../session-ui/src/components/basic-tool.css | 1 - .../src/components/message-part.css | 12 +----- 5 files changed, 61 insertions(+), 26 deletions(-) diff --git a/packages/app/src/shell/panel-motion.test.ts b/packages/app/src/shell/panel-motion.test.ts index d83a665bb39..8ea29992797 100644 --- a/packages/app/src/shell/panel-motion.test.ts +++ b/packages/app/src/shell/panel-motion.test.ts @@ -1,9 +1,9 @@ import { expect, it } from "bun:test" -import { panelSpring } from "./panel-motion" +import { panelOpacity, panelSpring } from "./panel-motion" const shared = { duration: 0.3, bounce: 0 } -const scale = { min: 0.15, max: 0.45, reference: 480 } +const scale = { min: 0.15, max: 0.3, reference: 480 } it("scales the shared spring's time by the square root of the distance against the reference width", () => { expect(panelSpring(480, shared, scale)).toEqual(shared) @@ -14,7 +14,7 @@ it("scales the shared spring's time by the square root of the distance against t it("clamps the scaled time between the min and max durations", () => { expect(panelSpring(40, shared, scale).duration).toBe(0.15) - expect(panelSpring(2000, shared, scale).duration).toBe(0.45) + expect(panelSpring(2000, shared, scale).duration).toBe(0.3) expect(panelSpring(40, shared, { ...scale, min: 0.2 }).duration).toBe(0.2) expect(panelSpring(2000, shared, { ...scale, max: 0.6 }).duration).toBe(0.6) }) @@ -32,3 +32,11 @@ it("keeps the shared spring when scaling is off or the distance is unknown", () expect(panelSpring(undefined, shared, scale)).toEqual(shared) expect(panelSpring(0, shared, scale)).toEqual(shared) }) + +it("keeps a panel's contents solid until the last stretch of travel before closed", () => { + expect(panelOpacity(0)).toBe("") + expect(panelOpacity(0.5)).toBe("1") + expect(panelOpacity(0.85)).toBe("1") + expect(Number(panelOpacity(0.925))).toBeCloseTo(0.5, 5) + expect(panelOpacity(1)).toBe("0") +}) diff --git a/packages/app/src/shell/panel-motion.ts b/packages/app/src/shell/panel-motion.ts index ce3763822a4..35c3bb6c3f7 100644 --- a/packages/app/src/shell/panel-motion.ts +++ b/packages/app/src/shell/panel-motion.ts @@ -51,7 +51,7 @@ const minDuration = distanceKnob("min", { unit: "s", }) -const maxDuration = distanceKnob("max", { label: "Max duration", value: 0.45, min: 0.2, max: 1, step: 0.01, unit: "s" }) +const maxDuration = distanceKnob("max", { label: "Max duration", value: 0.3, min: 0.2, max: 1, step: 0.01, unit: "s" }) // The width whose flight takes the shared spring's own time. const referenceWidth = distanceKnob("reference", { @@ -93,19 +93,38 @@ const style = motionTuning.choice("sidebars.style", { labels: { spring: "Spring", instant: "Instant" }, }) -// How far a panel's contents dim at the closed end of a spring flight; they never black out. -const fadeFloor = motionTuning.number("sidebars.fadeFloor", { - label: "Fade floor", +// How a panel's contents fade on a spring flight: only across the last stretch of travel before closed, so they stay +// solid for most of a close and arrive almost at once on an open; not at all; or across the whole flight, down to half. +const contentsFade = motionTuning.choice("sidebars.contentsFade", { + label: "Contents fade", group, when: springs, - value: 0.5, - min: 0, - max: 1, - step: 0.05, + value: "edge", + labels: { edge: "Edge", off: "Off", spring: "Whole spring" }, }) -/** The opacity of a panel's contents `closed` of the way through a spring flight, from 1 down to the fade floor. */ -export const panelOpacity = (closed: number) => (closed === 0 || james() ? "" : `${1 - closed * (1 - fadeFloor())}`) +const edgeFade = motionTuning.number("sidebars.edgeFade", { + label: "Edge fade", + group, + when: () => springs() && contentsFade() === "edge", + value: 15, + min: 5, + max: 50, + step: 1, + unit: "%", +}) + +/** The opacity of a panel's contents `closed` of the way through a spring flight, as the contents fade sets it. */ +export const panelOpacity = (closed: number) => { + if (closed === 0 || james()) return "" + const fade = contentsFade() + + if (fade === "off") return "" + + if (fade === "spring") return `${1 - closed / 2}` + + return `${Math.min(1, (1 - closed) / (edgeFade() / 100))}` +} const jamesShift = motionTuning.spring("sidebars.james.shift", { label: "Movement", diff --git a/packages/app/test-browser/panel-motion.test.ts b/packages/app/test-browser/panel-motion.test.ts index 68da8177e6e..fbc45d23ccd 100644 --- a/packages/app/test-browser/panel-motion.test.ts +++ b/packages/app/test-browser/panel-motion.test.ts @@ -44,6 +44,12 @@ function setStyle(value: string) { if (knob?.kind === "choice") motionTuning.set(knob, value) } +function setContentsFade(value: string) { + const knob = motionTuning.list().find((item) => item.id === "sidebars.contentsFade") + + if (knob?.kind === "choice") motionTuning.set(knob, value) +} + // James is a mode, chosen in the preset strip rather than the Motion choice. function setJames(on: boolean) { const knob = motionTuning.list().find((item) => item.id === "sidebars.james") @@ -446,11 +452,22 @@ it("swaps the spring knobs for James's while it's on", () => { .filter((knob) => knob.group === "Sidebars" && knob.kind !== "mode" && (knob.when?.() ?? true)) .map((knob) => knob.label) - expect(shown()).toEqual(["Spring", "Motion", "Fade floor"]) + expect(shown()).toEqual(["Spring", "Motion", "Contents fade", "Edge fade"]) setJames(true) expect(shown()).toEqual(["Movement", "Fade", "Fade duration", "Panel shift", "Layout", "Layout open", "Layout close"]) setJames(false) - expect(shown()).toEqual(["Spring", "Motion", "Fade floor"]) + expect(shown()).toEqual(["Spring", "Motion", "Contents fade", "Edge fade"]) +}) + +it("shows the edge fade's length only while the contents fade at the edge", () => { + const edge = motionTuning.list().find((item) => item.id === "sidebars.edgeFade") + cleanups.push(() => setContentsFade("edge")) + + expect(edge?.when?.()).toBe(true) + setContentsFade("spring") + expect(edge?.when?.()).toBe(false) + setContentsFade("off") + expect(edge?.when?.()).toBe(false) }) it("ships the spring as the default sidebar motion, with James one choice away", () => { diff --git a/packages/session-ui/src/components/basic-tool.css b/packages/session-ui/src/components/basic-tool.css index 478c980e2ec..1b5a7fc9a9f 100644 --- a/packages/session-ui/src/components/basic-tool.css +++ b/packages/session-ui/src/components/basic-tool.css @@ -202,7 +202,6 @@ align-items: center; flex-shrink: 0; opacity: 0; - transition: opacity 0.15s ease; } /* Reveal the action while the pointer is anywhere over the tool, including its expanded content. */ diff --git a/packages/session-ui/src/components/message-part.css b/packages/session-ui/src/components/message-part.css index d016aac7a0a..02f1fcf79ea 100644 --- a/packages/session-ui/src/components/message-part.css +++ b/packages/session-ui/src/components/message-part.css @@ -234,8 +234,8 @@ justify-content: flex-end; gap: 8px; width: 100%; - transition: opacity 200ms ease-out; + /* Hover actions show and hide at once, without a fade. */ @media (hover: hover) { opacity: 0; pointer-events: none; @@ -309,7 +309,6 @@ flex: 0 0 auto; white-space: nowrap; text-align: end; - transition: opacity 200ms ease-out; @media (hover: hover) { opacity: 0; @@ -365,8 +364,6 @@ :root[data-motion="reduce"] &, &[data-delivering], [data-timeline-grow] & { - [data-slot="user-message-copy-wrapper"], - [data-slot="user-message-meta-tail"], [data-slot="user-message-transition"] { transition: none; } @@ -454,8 +451,8 @@ align-items: center; justify-content: flex-start; gap: 8px; - transition: opacity 200ms ease-out; + /* Hover actions show and hide at once, without a fade. */ @media (hover: hover) { opacity: 0; pointer-events: none; @@ -1735,7 +1732,6 @@ inset-inline-end: -28px; z-index: 1; display: flex; - transition: opacity 150ms ease-out; @media (hover: hover) { opacity: 0; @@ -1747,10 +1743,6 @@ [data-slot="message-options"]:has([data-expanded]) { opacity: 1; } - - :root[data-motion="reduce"] & [data-slot="message-options"] { - transition: none; - } } /* Centered on the bubble's first line. */