Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<article>` 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).
Expand Down
2 changes: 1 addition & 1 deletion frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
See the [VM guide](../docs/vm.md).
19 changes: 19 additions & 0 deletions frontend/e2e/search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/ui/SearchForm.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

.field:focus-within {
border-color: var(--color-focus);
outline: 3px solid var(--field-focus-ring, transparent);
}

.icon {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/features/landing/components/Hero.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 25 additions & 0 deletions frontend/src/features/search/SearchView.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.page {
position: relative;
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: var(--space-4);
Expand All @@ -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);
Expand Down
15 changes: 13 additions & 2 deletions frontend/src/features/search/SearchView.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -65,6 +65,7 @@ export function SearchView(props: SearchViewProps) {
const listRef = useRef<HTMLUListElement>(null);
const firstNewWine = useRef<number | null>(null);
const headingRef = useRef<HTMLHeadingElement>(null);
const statusRef = useRef<HTMLParagraphElement>(null);
const { search } = useLocation();
const previousSearch = useRef(search);

Expand All @@ -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<HTMLAnchorElement>) {
event.preventDefault();
statusRef.current?.focus();
}

const noHits = !loading && !error && totalCount === 0;
const filterPanel = (
<FilterPanel
Expand All @@ -108,6 +115,10 @@ export function SearchView(props: SearchViewProps) {
Utforsk viner
</h1>

<a href="#results" className={styles.skipLink} onClick={skipToResults}>
Hopp til resultatene
</a>

<SearchForm
label="Søk etter vin"
size="lg"
Expand All @@ -129,7 +140,7 @@ export function SearchView(props: SearchViewProps) {
<div className={styles.results}>
<div className={styles.toolbar}>
{/* Always in the DOM, so changes are announced. */}
<p role="status" className={styles.status}>
<p id="results" ref={statusRef} tabIndex={-1} role="status" className={styles.status}>
{describeStatus(props)}
</p>
<div className={styles.controls}>
Expand Down