Skip to content

Commit 66df205

Browse files
saphidclaude
andcommitted
fix(web): send-anchor scroll also respects Reduce Motion
Sending a message while scrolled away from the end glided the new message to the top even with Reduce Motion on. The anchor scroll now reads the preference when it runs and jumps instead; settling still waits for `scrollend` or the fallback timer, which an instant scroll also triggers. Also cover held PageUp/PageDown under reduced motion: holding the key is the user moving the page, so it stays continuous and stops on release. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 105bfb9 commit 66df205

2 files changed

Lines changed: 31 additions & 24 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6757,9 +6757,11 @@ export default function ChatView(props: ChatViewProps) {
67576757
};
67586758
const fallbackTimer = window.setTimeout(finishAnimatedPositioning, 750);
67596759
scrollNode.addEventListener("scrollend", finishAnimatedPositioning, { once: true });
6760+
// An instant scroll also ends with `scrollend` (or the fallback when nothing moved), so it
6761+
// settles the same way.
67606762
void list.scrollToIndex({
67616763
index: anchorIndex,
6762-
animated: true,
6764+
animated: !window.matchMedia("(prefers-reduced-motion: reduce)").matches,
67636765
viewPosition: 0,
67646766
viewOffset: CHAT_LIST_ANCHOR_OFFSET,
67656767
});

‎apps/web/src/components/chat/pageScrollController.test.ts‎

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -264,33 +264,38 @@ describe("createPageScrollController", () => {
264264
expect(container.scrollTop).toBeCloseTo(pageDistance * 2, 5);
265265
});
266266

267-
test("continues scrolling on hold without repeated keydown events and stops on keyup", () => {
268-
const clock = new TestClock();
269-
const container = {
270-
clientHeight: 600,
271-
scrollHeight: 4_000,
272-
scrollTop: 0,
273-
getBoundingClientRect: () => ({ height: 600 }),
274-
};
275-
const controller = createPageScrollController({
276-
getContainer: () => container,
277-
getScrollPaddingBottomPx: () => 24,
278-
env: clock.env,
279-
});
280-
controller.handleKeyDown("PageDown");
281-
clock.advanceBy(PAGE_SCROLL_ANIMATION_MS + 50);
267+
// Holding the key is the user moving the page, so it stays continuous under reduced motion.
268+
test.each([false, true])(
269+
"continues scrolling on hold without repeated keydown events and stops on keyup (reduced motion: %s)",
270+
(reducedMotion) => {
271+
const clock = new TestClock();
272+
clock.reducedMotion = reducedMotion;
273+
const container = {
274+
clientHeight: 600,
275+
scrollHeight: 4_000,
276+
scrollTop: 0,
277+
getBoundingClientRect: () => ({ height: 600 }),
278+
};
279+
const controller = createPageScrollController({
280+
getContainer: () => container,
281+
getScrollPaddingBottomPx: () => 24,
282+
env: clock.env,
283+
});
284+
controller.handleKeyDown("PageDown");
285+
clock.advanceBy(PAGE_SCROLL_ANIMATION_MS + 50);
282286

283-
const afterHoldStarts = container.scrollTop;
284-
clock.advanceBy(200);
287+
const afterHoldStarts = container.scrollTop;
288+
clock.advanceBy(200);
285289

286-
expect(container.scrollTop).toBeGreaterThan(afterHoldStarts);
290+
expect(container.scrollTop).toBeGreaterThan(afterHoldStarts);
287291

288-
const stoppedAt = container.scrollTop;
289-
controller.handleKeyUp("PageDown");
290-
clock.advanceBy(250);
292+
const stoppedAt = container.scrollTop;
293+
controller.handleKeyUp("PageDown");
294+
clock.advanceBy(250);
291295

292-
expect(container.scrollTop).toBe(stoppedAt);
293-
});
296+
expect(container.scrollTop).toBe(stoppedAt);
297+
},
298+
);
294299

295300
test("notifies once when a page scroll starts", () => {
296301
const clock = new TestClock();

0 commit comments

Comments
 (0)