diff --git a/web/src/components/layout/Shell.test.tsx b/web/src/components/layout/Shell.test.tsx index 75c95f6..8819402 100644 --- a/web/src/components/layout/Shell.test.tsx +++ b/web/src/components/layout/Shell.test.tsx @@ -1,5 +1,6 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { render, screen, within } from '@testing-library/react' +import userEvent from '@testing-library/user-event' import { createMemoryRouter, RouterProvider } from 'react-router-dom' import { beforeEach, expect, test, vi } from 'vitest' import { sessionStore } from '@/auth/session' @@ -165,3 +166,13 @@ test('an unknown path shows the not-found page with a way back', () => { expect(screen.getByRole('heading', { name: 'This page does not exist' })).toBeInTheDocument() expect(screen.getByRole('link', { name: 'Back to Home' })).toHaveAttribute('href', '/') }) + +test('a skip link comes first and moves the focus to the page', async () => { + const user = userEvent.setup() + renderAt('/artists') + await user.tab() + const skip = screen.getByRole('link', { name: 'Skip to content' }) + expect(skip).toHaveFocus() + await user.keyboard('{Enter}') + expect(screen.getByRole('main')).toHaveFocus() +}) diff --git a/web/src/components/layout/Shell.tsx b/web/src/components/layout/Shell.tsx index df9b2c1..691424f 100644 --- a/web/src/components/layout/Shell.tsx +++ b/web/src/components/layout/Shell.tsx @@ -1,3 +1,5 @@ +import { useRef } from 'react' +import { useTranslation } from 'react-i18next' import { Outlet } from 'react-router-dom' import { usePlayerEngine } from '@/player/usePlayer' import UpdateNotice from '@/pwa/UpdateNotice' @@ -6,12 +8,30 @@ import Sidebar from './Sidebar' /** The frame of the app: the sidebar, the page, and the player bar. */ export default function Shell() { + const { t } = useTranslation() + const main = useRef(null) usePlayerEngine() return (
+ {/* The first stop of the Tab key: it jumps over the sidebar. It moves the focus itself, so the address does not change. */} + { + e.preventDefault() + main.current?.focus() + }} + className="sr-only focus-visible:not-sr-only focus-visible:fixed focus-visible:top-2 focus-visible:left-2 focus-visible:z-50 focus-visible:rounded-md focus-visible:bg-primary focus-visible:px-4 focus-visible:py-2 focus-visible:font-bold focus-visible:text-primary-foreground" + > + {t('app.skip')} +
-
+
diff --git a/web/src/i18n/locales/en.json b/web/src/i18n/locales/en.json index df8248c..cc914cd 100644 --- a/web/src/i18n/locales/en.json +++ b/web/src/i18n/locales/en.json @@ -1,6 +1,7 @@ { "app": { "name": "Sonda", + "skip": "Skip to content", "privacy": "Nothing leaves this server unless an admin turns a provider on." }, "nav": { diff --git a/web/src/i18n/locales/it.json b/web/src/i18n/locales/it.json index a699824..50f0eb2 100644 --- a/web/src/i18n/locales/it.json +++ b/web/src/i18n/locales/it.json @@ -1,6 +1,7 @@ { "app": { "name": "Sonda", + "skip": "Vai al contenuto", "privacy": "Niente esce da questo server finché un admin non accende un provider." }, "nav": {