From 331cf3ec9efe73a7e61992bf489d3388c179564a Mon Sep 17 00:00:00 2001 From: Erik Hjelm Fjeldheim Date: Fri, 20 Nov 2026 14:16:45 -0600 Subject: [PATCH] fix: #102 keep Back to Top floating as a compact circle on mobile --- client/src/components/BackToTop.css | 24 ++++++++++++++++-------- client/src/components/BackToTop.test.tsx | 20 +++++++++++++++++++- client/src/components/BackToTop.tsx | 6 ++++-- client/src/components/ResultsLayout.css | 6 ++++++ docs/AI-USAGE.md | 1 + 5 files changed, 46 insertions(+), 11 deletions(-) diff --git a/client/src/components/BackToTop.css b/client/src/components/BackToTop.css index 015f556..6b04977 100644 --- a/client/src/components/BackToTop.css +++ b/client/src/components/BackToTop.css @@ -1,16 +1,16 @@ .back-to-top { position: fixed; - right: max(0.75rem, env(safe-area-inset-right)); - top: max(1rem, env(safe-area-inset-top)); + right: max(1rem, env(safe-area-inset-right)); + bottom: max(1.25rem, env(safe-area-inset-bottom)); z-index: 2; - display: flex; + display: inline-flex; align-items: center; justify-content: center; gap: 0.375rem; width: fit-content; max-width: calc(100% - 1.5rem); min-height: 2.75rem; - padding: 0.5rem; + padding: 0.5rem 0.875rem; border: 1px solid var(--accent); border-radius: 100px; background: var(--surface); @@ -20,8 +20,9 @@ font-weight: 700; } -.back-to-top span { +.back-to-top__icon { font-size: 1.25rem; + line-height: 1; } .back-to-top:hover { @@ -31,8 +32,15 @@ @media (max-width: 700px) { .back-to-top { - /* Keep narrow-screen controls clear, including with enlarged text. */ - position: static; - margin: 1.5rem 0 0 auto; + right: max(0.75rem, env(safe-area-inset-right)); + bottom: max(1rem, env(safe-area-inset-bottom)); + width: 2.75rem; + height: 2.75rem; + padding: 0; + border-radius: 50%; + } + + .back-to-top__label { + display: none; } } diff --git a/client/src/components/BackToTop.test.tsx b/client/src/components/BackToTop.test.tsx index f639c8a..434ade6 100644 --- a/client/src/components/BackToTop.test.tsx +++ b/client/src/components/BackToTop.test.tsx @@ -1,6 +1,7 @@ import { afterEach, expect, it, vi } from 'vitest'; import { fireEvent, render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; +import axe from 'axe-core'; import BackToTop from './BackToTop.js'; @@ -16,7 +17,13 @@ it('appears after 600px, hides near the top and removes its listener on unmount' expect(screen.queryByRole('button', { name: 'Back to top' })).not.toBeInTheDocument(); vi.stubGlobal('scrollY', 601); fireEvent.scroll(window); - expect(screen.getByRole('button', { name: 'Back to top' })).toHaveTextContent('Top'); + const button = screen.getByRole('button', { name: 'Back to top' }); + expect(button).toHaveTextContent('Top'); + expect(button.querySelector('.back-to-top__icon')).toHaveAttribute( + 'aria-hidden', + 'true', + ); + expect(button.querySelector('.back-to-top__label')).toHaveTextContent('Top'); vi.stubGlobal('scrollY', 600); fireEvent.scroll(window); expect(screen.queryByRole('button', { name: 'Back to top' })).not.toBeInTheDocument(); @@ -24,6 +31,17 @@ it('appears after 600px, hides near the top and removes its listener on unmount' expect(removeListener).toHaveBeenCalledWith('scroll', expect.any(Function)); }); +it('keeps an accessible label and passes axe when visible', async () => { + vi.stubGlobal('scrollY', 650); + const { container } = render(); + const button = screen.getByRole('button', { name: 'Back to top' }); + expect(button).toHaveAttribute('aria-label', 'Back to top'); + const results = await axe.run(container, { + rules: { 'color-contrast': { enabled: false } }, + }); + expect(results.violations).toEqual([]); +}); + it.each([ ['click', false, 'smooth'], ['{Enter}', false, 'smooth'], diff --git a/client/src/components/BackToTop.tsx b/client/src/components/BackToTop.tsx index c379e3c..8b8dc65 100644 --- a/client/src/components/BackToTop.tsx +++ b/client/src/components/BackToTop.tsx @@ -30,8 +30,10 @@ export default function BackToTop() { }); }} > - - Top + + Top ); } diff --git a/client/src/components/ResultsLayout.css b/client/src/components/ResultsLayout.css index 0dae989..32f93ce 100644 --- a/client/src/components/ResultsLayout.css +++ b/client/src/components/ResultsLayout.css @@ -1,6 +1,12 @@ .results { padding-bottom: 2.5rem; } +@media (max-width: 700px) { + /* Leave clearance above the floating bottom-right Back to top button. */ + .results { + padding-bottom: 4.5rem; + } +} .results-header { margin-bottom: 1rem; } diff --git a/docs/AI-USAGE.md b/docs/AI-USAGE.md index 745f626..dca1e8f 100644 --- a/docs/AI-USAGE.md +++ b/docs/AI-USAGE.md @@ -104,6 +104,7 @@ the part that matters most. | 2026-11-13 | robertky | Codex (ChatGPT) | Assisted me with #26: polished the README, added screenshots and project-document links, and verified the local setup from a clean clone. I reviewed the changes and updated the implementation notes to reflect merged browsing and country-filter features. | | 2026-11-17 | erikhfj | Antigravity | #91, E2E search helper fix: updated `e2e/tests/search.spec.ts` to match the `Search` and `Filters` buttons with `exact: true` so `Clear recent searches` does not trigger a strict-mode violation, and cleared `E2E_USER_ID`'s recorded search history during cleanup. Verified locally with two consecutive full `pnpm test:e2e` runs against a throwaway seeded PostgreSQL stack. | | 2026-11-20 | erikhfj | Antigravity | #100, review author privacy: removed `User.id` from `schema.graphql` and the `AlbumDetail` query, replaced `Listener ` with deterministic SHA-256 music pseudonyms in `server/src/userIdentity.ts` (including read-time sanitization of legacy labels in `Review.user`), added `User` cache merge policy, and updated schema/unit/client tests and `docs/architecture.md`. Verified with `pnpm codegen`, `pnpm format:check`, `pnpm lint`, `pnpm typecheck`, `pnpm test`, and `pnpm build`. | +| 2026-11-20 | erikhfj | Antigravity | #102, floating mobile Back to Top button: positioned `BackToTop` fixed at bottom-right across viewports with a compact 44px circular icon-only layout on mobile (`<= 700px`), preserved the `Back to top` accessible name, added bottom clearance on `.results` so controls such as `Load more` stay unobstructed, and expanded `BackToTop.test.tsx`. Verified with `pnpm format:check && pnpm lint && pnpm typecheck && pnpm test && pnpm build`. | ## Notes