feat(web): a skip link jumps over the sidebar to the page

This commit is contained in:
tgiachi 2026-11-13 12:44:12 +01:00
commit a80ead7f2b
4 changed files with 34 additions and 1 deletions

View file

@ -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()
})

View file

@ -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<HTMLElement>(null)
usePlayerEngine()
return (
<div className="flex min-h-screen flex-col bg-background text-foreground">
{/* The first stop of the Tab key: it jumps over the sidebar. It moves the focus itself, so the address does not change. */}
<a
href="#main"
onClick={(e) => {
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')}
</a>
<div className="flex flex-1 flex-wrap gap-2 p-2">
<Sidebar />
<main className="min-w-0 flex-[999_1_560px] rounded-xl bg-card p-6 text-card-foreground">
<main
id="main"
ref={main}
tabIndex={-1}
className="min-w-0 flex-[999_1_560px] rounded-xl bg-card p-6 text-card-foreground outline-none"
>
<Outlet />
</main>
</div>

View file

@ -1,6 +1,7 @@
{
"app": {
"name": "Sonda",
"skip": "Skip to content",
"privacy": "Nothing leaves this server unless an admin turns a provider on."
},
"nav": {

View file

@ -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": {