From 025f1ff9471eb433e199d22b34adf6a9eb655201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20=C3=98rjavik?= Date: Mon, 16 Nov 2026 15:15:25 +0100 Subject: [PATCH 1/2] feat(a11y): add a skip-to-content link Keyboard users had to tab through the whole header on every page. A "Skip to main content" link is now the first tab stop: hidden until focused, then shown top left in white on the dark text colour. It moves focus to
without adding a hash to the URL. Browser test covers focus order, visibility, colours and the focus move. Closes #102 --- .../components/shell/AppShell/AppShell.css | 29 +++++++++++++++++++ .../components/shell/AppShell/AppShell.tsx | 18 +++++++++++- e2e/smoke.spec.ts | 26 +++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/shell/AppShell/AppShell.css b/apps/web/src/components/shell/AppShell/AppShell.css index e945a95..f2f2600 100644 --- a/apps/web/src/components/shell/AppShell/AppShell.css +++ b/apps/web/src/components/shell/AppShell/AppShell.css @@ -9,4 +9,33 @@ ), var(--color-bg-page); } + + /* Off-screen until it receives keyboard focus, then shown top left. */ + .app-shell__skip-link { + position: absolute; + z-index: var(--z-modal); + top: var(--space-2); + left: var(--space-2); + + padding: var(--space-2) var(--space-4); + + border-radius: var(--radius-md); + + color: var(--color-text-inverse); + background-color: var(--color-text-primary); + + font-weight: var(--font-weight-semibold); + text-decoration: none; + + transform: translateY(calc(-100% - var(--space-4))); + } + + .app-shell__skip-link:focus { + transform: none; + } + + /* Main is only focused as a skip-link or navigation target, not typed in. */ + .app-shell main:focus { + outline: none; + } } diff --git a/apps/web/src/components/shell/AppShell/AppShell.tsx b/apps/web/src/components/shell/AppShell/AppShell.tsx index 195600a..f4cd171 100644 --- a/apps/web/src/components/shell/AppShell/AppShell.tsx +++ b/apps/web/src/components/shell/AppShell/AppShell.tsx @@ -6,8 +6,24 @@ import './AppShell.css'; function AppShell() { return (
+ {/* + * First focusable element: lets keyboard users skip the header. + * Hidden until focused (AppShell.css). Main is focusable (tabIndex -1) + * so focus actually moves there, not only the scroll position. + */} + { + // Focus main directly instead of adding #main-content to the URL. + event.preventDefault(); + document.getElementById('main-content')?.focus(); + }} + > + Skip to main content + -
+
diff --git a/e2e/smoke.spec.ts b/e2e/smoke.spec.ts index 6b2ba23..68af88c 100644 --- a/e2e/smoke.spec.ts +++ b/e2e/smoke.spec.ts @@ -356,3 +356,29 @@ test('keeps recipe-specific not-found handling separate from the global 404', as page.getByRole('heading', { name: 'Page not found' }), ).not.toBeVisible(); }); + +test('skip link is the first tab stop, visible on focus, and moves focus to main', async ({ + page, +}) => { + await page.setViewportSize({ width: 1280, height: 800 }); + await page.goto('.'); + await expect( + page.getByRole('heading', { name: 'Explore Recipes' }), + ).toBeVisible(); + const skip = page.getByRole('link', { name: 'Skip to main content' }); + await expect(skip).not.toBeInViewport(); + await page.keyboard.press('Tab'); + await expect(skip).toBeFocused(); + await expect(skip).toBeInViewport(); + // Light text on the dark text colour: well above the 4.5:1 AA minimum. + await expect(skip).toHaveCSS('color', 'rgb(255, 255, 255)'); + await expect(skip).toHaveCSS('background-color', 'rgb(15, 23, 42)'); + await page.keyboard.press('Enter'); + await expect(page.locator('main#main-content')).toBeFocused(); + await expect(page).not.toHaveURL(/#main-content/); + // The next Tab continues inside the page content, not in the header. + await page.keyboard.press('Tab'); + expect( + await page.evaluate(() => Boolean(document.activeElement?.closest('main'))), + ).toBe(true); +}); From 55fe01886e301f96ef9cb276cf4c17af13ded741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20=C3=98rjavik?= Date: Tue, 17 Nov 2026 00:53:14 +0100 Subject: [PATCH 2/2] fix(a11y): keep the skip-link target clear of the sticky header Focusing
on a scrolled-down page scrolled it behind the sticky header, hiding its first control (e.g. Back on recipe detail). main now has scroll-margin-top of the header height (new --site-header-height token, also used by the header). E2E: on a long, scrolled recipe page, skip link then Tab focuses Back fully in view and below the header. --- .../components/shell/AppShell/AppShell.css | 8 +++ .../shell/SiteHeader/SiteHeader.css | 4 +- apps/web/src/styles/tokens.css | 2 + e2e/smoke.spec.ts | 55 +++++++++++++++++++ 4 files changed, 67 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/shell/AppShell/AppShell.css b/apps/web/src/components/shell/AppShell/AppShell.css index f2f2600..4c1b55a 100644 --- a/apps/web/src/components/shell/AppShell/AppShell.css +++ b/apps/web/src/components/shell/AppShell/AppShell.css @@ -34,6 +34,14 @@ transform: none; } + /* + * Focusing main scrolls it into view. On a scrolled-down page it would + * otherwise end up behind the sticky header, hiding its first control. + */ + .app-shell main { + scroll-margin-top: calc(var(--site-header-height) + var(--space-2)); + } + /* Main is only focused as a skip-link or navigation target, not typed in. */ .app-shell main:focus { outline: none; diff --git a/apps/web/src/components/shell/SiteHeader/SiteHeader.css b/apps/web/src/components/shell/SiteHeader/SiteHeader.css index 9dabf39..cb557d2 100644 --- a/apps/web/src/components/shell/SiteHeader/SiteHeader.css +++ b/apps/web/src/components/shell/SiteHeader/SiteHeader.css @@ -12,7 +12,7 @@ display: flex; align-items: center; gap: var(--space-8); - min-height: 5rem; + min-height: var(--site-header-height); } .brand { @@ -112,7 +112,7 @@ .site-header__inner { flex-wrap: wrap; gap: 0; - min-height: 5rem; + min-height: var(--site-header-height); padding-block: var(--space-3); } diff --git a/apps/web/src/styles/tokens.css b/apps/web/src/styles/tokens.css index ef84314..89924dd 100644 --- a/apps/web/src/styles/tokens.css +++ b/apps/web/src/styles/tokens.css @@ -209,6 +209,8 @@ /* Layering */ --z-dropdown: 100; --z-sticky: 200; + /* Height of the sticky site header; content scrolled to must clear it. */ + --site-header-height: 5rem; --z-overlay: 300; --z-modal: 400; diff --git a/e2e/smoke.spec.ts b/e2e/smoke.spec.ts index 68af88c..2598a15 100644 --- a/e2e/smoke.spec.ts +++ b/e2e/smoke.spec.ts @@ -382,3 +382,58 @@ test('skip link is the first tab stop, visible on focus, and moves focus to main await page.evaluate(() => Boolean(document.activeElement?.closest('main'))), ).toBe(true); }); + +test('after the skip link on a scrolled page, the next control is not under the header', async ({ + page, +}) => { + await page.setViewportSize({ width: 1280, height: 700 }); + const longRecipe: RecipeFieldsFragment = { + ...recipe, + description: 'A long description. '.repeat(40), + ingredients: Array.from({ length: 15 }, (_, index) => ({ + id: `ingredient-${index}`, + name: `Ingredient ${index + 1}`, + amount: index + 1, + unit: 'g', + note: null, + })), + instructions: Array.from({ length: 10 }, (_, index) => ({ + step: index + 1, + text: 'Stir and simmer for a while. '.repeat(6), + })), + }; + await page.route('**/project2/api/graphql', async (route) => { + const body = route.request().postDataJSON() as { query?: string }; + await route.fulfill({ + json: body.query?.includes('currentUser') + ? { data: { currentUser: null } } + : { data: { recipe: longRecipe } }, + }); + }); + await page.goto(`recipes/${recipe.id}`); + await expect( + page.getByRole('heading', { name: recipe.title, level: 1 }), + ).toBeVisible(); + // Read the recipe, scrolled well past the header area. + await page.mouse.wheel(0, 2000); + await expect + .poll(() => page.evaluate(() => window.scrollY)) + .toBeGreaterThan(500); + + await page.keyboard.press('Tab'); + await expect( + page.getByRole('link', { name: 'Skip to main content' }), + ).toBeFocused(); + await page.keyboard.press('Enter'); + await expect(page.locator('main#main-content')).toBeFocused(); + await page.keyboard.press('Tab'); + // The first control in main is the recipe's Back button: focused, in view + // and fully below the sticky header. + const back = page.getByRole('button', { name: /Back/ }); + await expect(back).toBeFocused(); + await expect(back).toBeInViewport({ ratio: 1 }); + const header = (await page.locator('.site-header').boundingBox())!; + expect((await back.boundingBox())!.y).toBeGreaterThanOrEqual( + header.y + header.height, + ); +});