diff --git a/e2e/scroll-bottom-indicator.spec.ts b/e2e/scroll-bottom-indicator.spec.ts new file mode 100644 index 00000000..a9622819 --- /dev/null +++ b/e2e/scroll-bottom-indicator.spec.ts @@ -0,0 +1,19 @@ +import { expect, test } from '@playwright/test' + +test('keeps the jump-to-bottom button visible while scrolling up', async ({ page }) => { + await page.goto('/e2e-fixtures/history-load-fixture.html?navigationShell=1') + await expect(page.getByText('Fixture message 1200', { exact: true })).toBeVisible() + await page.waitForTimeout(3500) + const viewport = page.locator('.chat-scroll-y') + const button = page.getByRole('button', { name: 'Scroll to bottom', exact: true }) + await expect(button).toHaveCount(0) + await viewport.hover() + await page.mouse.wheel(0, -500) + await expect(button).toBeVisible() + await page.mouse.wheel(0, -500) + await expect(button).toBeVisible() + if (process.env.HAPI_SCREENSHOT_PATH) await page.screenshot({ path: process.env.HAPI_SCREENSHOT_PATH }) + await button.click() + await expect(button).toHaveCount(0) + await expect.poll(() => viewport.evaluate(el => el.scrollHeight - el.scrollTop - el.clientHeight)).toBeLessThanOrEqual(1) +}) diff --git a/web/src/components/AssistantChat/HappyThread.mobile-scroll.test.tsx b/web/src/components/AssistantChat/HappyThread.mobile-scroll.test.tsx index b52769cd..06e65972 100644 --- a/web/src/components/AssistantChat/HappyThread.mobile-scroll.test.tsx +++ b/web/src/components/AssistantChat/HappyThread.mobile-scroll.test.tsx @@ -224,6 +224,25 @@ function renderSearchThread(options: { } describe('mobile initial scroll settling', () => { + it('shows the jump control during continuous upward scrolling and hides it at the bottom', () => { + const { viewport, queryByRole } = renderThread() + act(() => { vi.advanceTimersByTime(3_000) }) + viewport.scrollTop = 702 + fireEvent.scroll(viewport) + expect(queryByRole('button', { name: /scroll to bottom/i })).toBeNull() + + viewport.scrollTop = 600 + fireEvent.scroll(viewport) + expect(queryByRole('button', { name: /scroll to bottom/i })).not.toBeNull() + viewport.scrollTop = 400 + fireEvent.scroll(viewport) + expect(queryByRole('button', { name: /scroll to bottom/i })).not.toBeNull() + + viewport.scrollTop = 702 + fireEvent.scroll(viewport) + expect(queryByRole('button', { name: /scroll to bottom/i })).toBeNull() + }) + it('uses the explicit tail transition when a send requests a forced scroll', () => { const onViewModeChange = vi.fn() const onJumpToTail = vi.fn() diff --git a/web/src/components/AssistantChat/HappyThread.test.tsx b/web/src/components/AssistantChat/HappyThread.test.tsx index 333279ca..a2e1b957 100644 --- a/web/src/components/AssistantChat/HappyThread.test.tsx +++ b/web/src/components/AssistantChat/HappyThread.test.tsx @@ -338,7 +338,7 @@ describe('scroll anchor helpers', () => { }) }) - it('shows the jump button only while scrolling down away from the bottom', () => { + it('shows the jump button in either direction away from the bottom', () => { const downward = getScrollIntent({ scrollTop: 610, previousScrollTop: 590, @@ -360,7 +360,7 @@ describe('scroll anchor helpers', () => { expect(downward.isScrollingDown).toBe(true) expect(shouldShowScrollToBottomButton(downward)).toBe(true) - expect(shouldShowScrollToBottomButton(upward)).toBe(false) + expect(shouldShowScrollToBottomButton(upward)).toBe(true) expect(shouldShowScrollToBottomButton(atBottom)).toBe(false) }) @@ -370,7 +370,7 @@ describe('scroll anchor helpers', () => { expect(shouldRenderScrollToBottomButton(false, 0)).toBe(false) }) - it('keeps the jump button visible after downward scrolling stops', () => { + it('keeps the jump button visible when scrolling stops or reverses', () => { const downward = getScrollIntent({ scrollTop: 610, previousScrollTop: 590, @@ -392,7 +392,7 @@ describe('scroll anchor helpers', () => { expect(getScrollToBottomButtonVisibility(false, downward)).toBe(true) expect(getScrollToBottomButtonVisibility(true, stationary)).toBe(true) - expect(getScrollToBottomButtonVisibility(true, upward)).toBe(false) + expect(getScrollToBottomButtonVisibility(true, upward)).toBe(true) }) it('cancels initial scroll settling when the user scrolls up away from the bottom', () => { diff --git a/web/src/components/AssistantChat/HappyThread.tsx b/web/src/components/AssistantChat/HappyThread.tsx index bbe8b680..f6860192 100644 --- a/web/src/components/AssistantChat/HappyThread.tsx +++ b/web/src/components/AssistantChat/HappyThread.tsx @@ -204,20 +204,14 @@ export function getScrollIntent(params: { } export function shouldShowScrollToBottomButton(intent: ScrollIntent): boolean { - return intent.isScrollingDown && !intent.isNearBottom + return !intent.isNearBottom } export function getScrollToBottomButtonVisibility( - wasVisible: boolean, + _wasVisible: boolean, intent: ScrollIntent ): boolean { - if (intent.isNearBottom || intent.isScrollingUp) { - return false - } - if (intent.isScrollingDown) { - return true - } - return wasVisible + return shouldShowScrollToBottomButton(intent) } export function shouldRenderScrollToBottomButton( @@ -1314,6 +1308,7 @@ export function HappyThread(props: { if (isInitialScrollSettling()) { setShowScrollToBottom(false) if (shouldCancelInitialScrollSettling(intent, hadExplicitUpwardIntent)) { + setShowScrollToBottom(shouldShowScrollToBottomButton(intent)) initialScrollDeadlineRef.current = 0 clearInitialScrollTimers() setAutoScrollMode(false) @@ -1359,7 +1354,7 @@ export function HappyThread(props: { if (intent.isScrollingUp && intent.distanceFromBottom > MANUAL_SCROLL_EPSILON_PX) { tailScrollInProgressRef.current = false - setShowScrollToBottom(false) + setShowScrollToBottom(shouldShowScrollToBottomButton(intent)) setAutoScrollMode(false) setAtBottomMode(false) return