From 0755f70dd548c594345303440ff736eaafd93b3b Mon Sep 17 00:00:00 2001 From: Johannes Horn Date: Sun, 22 Nov 2026 13:42:12 +0100 Subject: [PATCH] feat(frontend): make the header sticky --- docs/accessibility.md | 2 ++ frontend/app/components/Header/Header.tsx | 4 +++- frontend/app/index.css | 5 +++++ frontend/app/routes/book/selectedBook.tsx | 2 +- frontend/app/routes/books.tsx | 2 +- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/accessibility.md b/docs/accessibility.md index 88612c0..89a3dfe 100644 --- a/docs/accessibility.md +++ b/docs/accessibility.md @@ -16,6 +16,8 @@ - **Communicating state.** The favorite button uses `aria-pressed`, the "Read more" button on the book page uses `aria-expanded`, and disabled pagination links use `aria-disabled` and are skipped when tabbing. Loading and empty search results are announced with `role="status"`. +- **A sticky header that does not hide the focus.** The header stays at the top of the screen while scrolling, so the navigation is always within reach, also on mobile (#165). A sticky header can cover the element that has keyboard focus, so we set `scroll-padding-top` to the height of the header. The browser then scrolls a focused element, and the target of the skip link, to below the header instead of behind it. + - **Responsive layout.** The book grid goes from four columns to one as the screen gets narrower, and the book page stacks vertically on small screens, so the app can be used on phones. ## Pointer cursor on interactive elements diff --git a/frontend/app/components/Header/Header.tsx b/frontend/app/components/Header/Header.tsx index c62c5d6..12ec4a8 100644 --- a/frontend/app/components/Header/Header.tsx +++ b/frontend/app/components/Header/Header.tsx @@ -9,7 +9,9 @@ function Header() { const { data: session, isPending } = authClient.useSession(); return ( -
+ // The header stays at the top while scrolling, so the navigation is always + // within reach. Its height is a CSS variable, see index.css +
{/* used strictly for inline text styling */} diff --git a/frontend/app/index.css b/frontend/app/index.css index dbf7080..ab57916 100644 --- a/frontend/app/index.css +++ b/frontend/app/index.css @@ -19,6 +19,9 @@ } html { @apply font-sans; + /* The header is sticky, so anchors and elements that get keyboard focus + must be scrolled to below it instead of behind it */ + scroll-padding-top: var(--header-height); } body { @@ -88,6 +91,8 @@ } :root { + /* The height of the sticky header. Other sticky elements are placed below it */ + --header-height: 4rem; color-scheme: light; --background: oklch(0.9659 0.0042 56.37); --foreground: oklch(0.145 0 0); diff --git a/frontend/app/routes/book/selectedBook.tsx b/frontend/app/routes/book/selectedBook.tsx index ee8cd45..a6ef958 100644 --- a/frontend/app/routes/book/selectedBook.tsx +++ b/frontend/app/routes/book/selectedBook.tsx @@ -160,7 +160,7 @@ export default function SelectedBookPage({ params }: Route.ComponentProps) {
- + diff --git a/frontend/app/routes/books.tsx b/frontend/app/routes/books.tsx index 0074ee9..0e389d5 100644 --- a/frontend/app/routes/books.tsx +++ b/frontend/app/routes/books.tsx @@ -82,7 +82,7 @@ function BooksLayout({