From d9c2bf37f6026c43b5e39d536fea9877d033724e Mon Sep 17 00:00:00 2001 From: SivertEikrem Date: Thu, 26 Nov 2026 20:08:52 +0100 Subject: [PATCH] =?UTF-8?q?feat(a11y):=20a=20focus=20ring=20that=20shows?= =?UTF-8?q?=20on=20wine=20red,=20and=20=C2=ABHopp=20til=20resultatene?= =?UTF-8?q?=C2=BB=20on=20/sok=20(#124)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- frontend/README.md | 2 +- frontend/e2e/search.spec.ts | 19 ++++++++++++++ .../src/components/ui/SearchForm.module.css | 1 + .../landing/components/Hero.module.css | 3 ++- .../src/features/search/SearchView.module.css | 25 +++++++++++++++++++ frontend/src/features/search/SearchView.tsx | 15 +++++++++-- 7 files changed, 62 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c15e222..1f40580 100644 --- a/README.md +++ b/README.md @@ -240,7 +240,7 @@ Our goal is WCAG 2.1 level AA. We design for users with reduced vision, hearing, ### Implemented - Semantic HTML: landmarks (`header`, `nav`, `main`, `footer`), one `h1` per page, lists for groups of cards, and `
` for each wine card. We try to use `div` and `span` only for layout. See [conventions](#code-quality-and-conventions). -- A skip link to the main content, and visible focus on all interactive elements. An end-to-end test tabs through the main pages and fails if an element gets focus without a visible mark. +- A skip link to the main content, and visible focus on all interactive elements. An end-to-end test tabs through the main pages and fails if an element gets focus without a visible mark. On the search page, «Hopp til resultatene» goes past the search field and the filters to the number of hits. The search field on the landing page has a light ring outside its border, so focus shows against the wine red as well as the white field (at least 6.5:1). - After navigation, focus moves to the page's `h1`. Screen reader users then hear that the page has changed. - Ratings are always shown as text, for example "4,6 av 5 · 23 dommer". The stars have a text alternative, so a screen reader reads «3,5 av 5 stjerner» instead of five images. - Giving a review works with the keyboard: the stars are radio buttons, so the arrow keys move through every half star, and each half is at least 24 × 24 px to click (WCAG 2.5.8). diff --git a/frontend/README.md b/frontend/README.md index 9057c79..f2da46f 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -15,4 +15,4 @@ Open the local URL printed by Vite. Vite forwards `/project2/graphql` to the bac To build and publish on the VM, run `./scripts/deploy.sh` from the repository root on the VM. It builds for `/project2/` and uses `sudo` to copy the output into `/var/www/html/project2`. -See the [VM guide](../docs/vm.md). \ No newline at end of file +See the [VM guide](../docs/vm.md). diff --git a/frontend/e2e/search.spec.ts b/frontend/e2e/search.spec.ts index 06ae251..2759cc5 100644 --- a/frontend/e2e/search.spec.ts +++ b/frontend/e2e/search.spec.ts @@ -145,6 +145,25 @@ test.describe('Søkesiden', () => { await expect(searchbox(page)).toBeFocused(); }); + test('«Hopp til resultatene» går forbi søkefeltet og filtrene', async ({ page }) => { + await stubApi(page); + await page.goto('./sok'); + await expect(results(page).getByRole('article')).toHaveCount(24); + + // «Hopp til hovedinnhold» first, and then the next Tab is the link to the results. + await page.keyboard.press('Tab'); + await page.keyboard.press('Enter'); + await page.keyboard.press('Tab'); + const skip = page.getByRole('link', { name: 'Hopp til resultatene' }); + await expect(skip).toBeFocused(); + await expect(skip).toBeVisible(); + + await page.keyboard.press('Enter'); + await expect(searchStatus(page)).toBeFocused(); + await expect(searchStatus(page)).toHaveText('Viser 24 av 30 viner'); + await expect(page).not.toHaveURL(/#results/); + }); + test('har ingen axe-brudd (WCAG 2.1 AA)', async ({ page }) => { await stubApi(page); await page.goto('./sok?q=pinot'); diff --git a/frontend/src/components/ui/SearchForm.module.css b/frontend/src/components/ui/SearchForm.module.css index c13ce06..406f67f 100644 --- a/frontend/src/components/ui/SearchForm.module.css +++ b/frontend/src/components/ui/SearchForm.module.css @@ -23,6 +23,7 @@ .field:focus-within { border-color: var(--color-focus); + outline: 3px solid var(--field-focus-ring, transparent); } .icon { diff --git a/frontend/src/features/landing/components/Hero.module.css b/frontend/src/features/landing/components/Hero.module.css index da77a3a..c05f1f3 100644 --- a/frontend/src/features/landing/components/Hero.module.css +++ b/frontend/src/features/landing/components/Hero.module.css @@ -46,8 +46,9 @@ .search { margin-top: var(--space-3); - /* Feltet ligger på hvit bakgrunn, men ledeteksten står på vinrødt. */ + /* The field is white, but its label and the ring around it stand on wine red. */ color: var(--color-on-brand); + --field-focus-ring: var(--color-focus-on-brand); } .chips { diff --git a/frontend/src/features/search/SearchView.module.css b/frontend/src/features/search/SearchView.module.css index 3ec9274..69cf916 100644 --- a/frontend/src/features/search/SearchView.module.css +++ b/frontend/src/features/search/SearchView.module.css @@ -1,4 +1,5 @@ .page { + position: relative; display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); @@ -9,6 +10,30 @@ font-size: var(--text-2xl); } +.skipLink:not(:focus) { + position: absolute; + width: 1px; + height: 1px; + overflow: hidden; + clip-path: inset(50%); + white-space: nowrap; +} + +.skipLink:focus { + position: absolute; + z-index: 10; + top: var(--space-2); + left: var(--space-4); + display: inline-flex; + align-items: center; + min-height: var(--tap-target); + padding: 0 var(--space-4); + border-radius: var(--radius-sm); + background: var(--color-accent); + color: var(--color-on-accent); + font-weight: 700; +} + .layout { display: grid; grid-template-columns: minmax(0, 1fr); diff --git a/frontend/src/features/search/SearchView.tsx b/frontend/src/features/search/SearchView.tsx index e6be315..a3b0b0f 100644 --- a/frontend/src/features/search/SearchView.tsx +++ b/frontend/src/features/search/SearchView.tsx @@ -1,4 +1,4 @@ -import { useEffect, useRef, useId } from 'react'; +import { useEffect, useRef, useId, type MouseEvent } from 'react'; import { useLocation } from 'react-router'; import { ErrorNotice } from '../../components/ui/ErrorNotice'; import { SearchForm } from '../../components/ui/SearchForm'; @@ -65,6 +65,7 @@ export function SearchView(props: SearchViewProps) { const listRef = useRef(null); const firstNewWine = useRef(null); const headingRef = useRef(null); + const statusRef = useRef(null); const { search } = useLocation(); const previousSearch = useRef(search); @@ -91,6 +92,12 @@ export function SearchView(props: SearchViewProps) { void loadMore(); } + // Past the search field and the filters, to the number of hits just above the results. + function skipToResults(event: MouseEvent) { + event.preventDefault(); + statusRef.current?.focus(); + } + const noHits = !loading && !error && totalCount === 0; const filterPanel = ( + + Hopp til resultatene + +
{/* Always in the DOM, so changes are announced. */} -

+

{describeStatus(props)}