Skip to content

Commit

Permalink
a11y: fix navigation title login
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurlbrjc committed Nov 4, 2024
1 parent 19c5ff1 commit 1febc14
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 68 deletions.
2 changes: 2 additions & 0 deletions app/(connected)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Metadata } from 'next'
import React, { ReactNode } from 'react'

import A11yPageTitle from 'components/A11yPageTitle'
import { MODAL_ROOT_ID } from 'components/globals'
import LiensEvitement from 'components/LiensEvitement'
import { estPassEmploi } from 'interfaces/conseiller'
Expand Down Expand Up @@ -33,6 +34,7 @@ export default async function LayoutWhenConnected({
return (
<>
<AppContextProviders conseiller={conseiller} portefeuille={portefeuille}>
<A11yPageTitle />
<LiensEvitement />

{children}
Expand Down
3 changes: 2 additions & 1 deletion app/(connexion)/login/cej/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
} from 'app/(connexion)/login/layout'

export const metadata: Metadata = {
title: "Connexion dans l'espace conseiller CEJ",
title:
"Connexion dans l'espace conseiller - Outil du Contrat d’Engagement Jeune",
}

export default async function LoginCEJ({
Expand Down
3 changes: 3 additions & 0 deletions app/(connexion)/login/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import { redirect } from 'next/navigation'
import React, { ReactNode, Suspense } from 'react'

import LayoutLoginClient from 'app/(connexion)/login/LayoutLoginClient'
import A11yPageTitle from 'components/A11yPageTitle'
import { MODAL_ROOT_ID } from 'components/globals'
import { getSessionServerSide } from 'utils/auth/auth'

export default function LayoutLogin({ children }: { children: ReactNode }) {
return (
<>
<A11yPageTitle />

<Suspense>
<LayoutLoginClient>{children}</LayoutLoginClient>
</Suspense>
Expand Down
3 changes: 2 additions & 1 deletion app/(connexion)/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
import LoginHubPage from 'app/(connexion)/login/LoginHubPage'

export const metadata: Metadata = {
title: 'Sélection de l’espace de connexion',
title:
'Sélection de l’espace de connexion - Outil du Contrat d’Engagement Jeune et du pass emploi',
}

export default async function LoginHub({
Expand Down
2 changes: 1 addition & 1 deletion app/(connexion)/login/passemploi/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import LoginPassEmploiPage from 'app/(connexion)/login/passemploi/LoginPassEmploiPage'

export const metadata: Metadata = {
title: "Connexion dans l'espace conseiller Pass Emploi",
title: "Connexion dans l'espace conseiller - Outil du pass emploi",
}

export default async function LoginPassEmploi({
Expand Down
22 changes: 22 additions & 0 deletions components/A11yPageTitle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use client'

import { usePathname } from 'next/navigation'
import React, { useEffect, useRef, useState } from 'react'

export default function A11yPageTitle() {
const pathname = usePathname()
const refContainer = useRef<HTMLDivElement>(null)

const [pageTitle, setPageTitle] = useState<string>()

useEffect(() => {
setPageTitle(document.title)
refContainer.current?.focus()
}, [pathname])

return (
<div ref={refContainer} tabIndex={-1} className='sr-only'>
{pageTitle}
</div>
)
}
66 changes: 24 additions & 42 deletions components/LiensEvitement.tsx
Original file line number Diff line number Diff line change
@@ -1,69 +1,51 @@
'use client'

import { usePathname } from 'next/navigation'
import React, { useEffect, useRef, useState } from 'react'
import React, { useEffect, useState } from 'react'

import { ID_CHAT, ID_CONTENU, ID_MENU } from 'components/globals'
import { useMobileViewport } from 'utils/mobileViewportContext'

export default function LiensEvitement() {
const pathname = usePathname()
const refContainer = useRef<HTMLDivElement>(null)

const isMobileViewport = useMobileViewport()

const [pageTitle, setPageTitle] = useState<string>()
const [pageHasChatAside, setPageHasChatAside] = useState<boolean>(false)

useEffect(() => {
setPageTitle(document.title)
}, [pathname])

useEffect(() => {
if (refContainer.current) {
refContainer.current.focus()
}
}, [pageTitle])

useEffect(() => {
setPageHasChatAside(Boolean(document.getElementById(ID_CHAT)))
}, [pageTitle])
}, [pathname])

if (isMobileViewport) return null

return (
<>
<div ref={refContainer} tabIndex={-1} className='sr-only'>
{pageTitle}
</div>
<ul className='sr-only focus-within:not-sr-only'>
<li>
<a
href={`#${ID_CONTENU}`}
className='text-primary_darken hover:text-primary'
>
Aller au contenu
</a>
</li>
<ul className='sr-only focus-within:not-sr-only'>
<li>
<a
href={`#${ID_CONTENU}`}
className='text-primary_darken hover:text-primary'
>
Aller au contenu
</a>
</li>
<li>
<a
href={`#${ID_MENU}`}
className='text-primary_darken hover:text-primary'
>
Aller au menu
</a>
</li>
{pageHasChatAside && (
<li>
<a
href={`#${ID_MENU}`}
href={`#${ID_CHAT}`}
className='text-primary_darken hover:text-primary'
>
Aller au menu
Aller aux conversations
</a>
</li>
{pageHasChatAside && (
<li>
<a
href={`#${ID_CHAT}`}
className='text-primary_darken hover:text-primary'
>
Aller aux conversations
</a>
</li>
)}
</ul>
</>
)}
</ul>
)
}
3 changes: 2 additions & 1 deletion tests/pages/LoginCEJPage.server.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ describe('LoginCEJPage server side', () => {

// Then
expect(metadata).toEqual({
title: "Connexion dans l'espace conseiller CEJ",
title:
"Connexion dans l'espace conseiller - Outil du Contrat d’Engagement Jeune",
})
expect(LoginCEJPage).toHaveBeenCalledWith({}, {})
})
Expand Down
3 changes: 2 additions & 1 deletion tests/pages/LoginHubPage.server.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ describe('LoginPage server side', () => {

// Then
expect(metadata).toEqual({
title: 'Sélection de l’espace de connexion',
title:
'Sélection de l’espace de connexion - Outil du Contrat d’Engagement Jeune et du pass emploi',
})
expect(LoginHubPage).toHaveBeenCalledWith({}, {})
})
Expand Down
2 changes: 1 addition & 1 deletion tests/pages/LoginPassEmploiPage.server.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('LoginPassEmploiPage server side', () => {

// Then
expect(metadata).toEqual({
title: "Connexion dans l'espace conseiller Pass Emploi",
title: "Connexion dans l'espace conseiller - Outil du pass emploi",
})
expect(LoginPassEmploiPage).toHaveBeenCalledWith(
{
Expand Down
40 changes: 20 additions & 20 deletions utils/AppContextProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,32 @@ export default function AppContextProviders({
})

return (
<ConseillerProvider conseiller={conseiller}>
<PortefeuilleProvider portefeuille={portefeuilleTrie}>
<ActualitesProvider>
<ChatCredentialsProvider>
<ChatsProvider>
<CurrentConversationProvider>
<ShowRubriqueListeDeDiffusionProvider>
<ListeDeDiffusionSelectionneeProvider>
<AlerteProvider>
<MobileViewportProvider>
<MobileViewportProvider>
<ConseillerProvider conseiller={conseiller}>
<PortefeuilleProvider portefeuille={portefeuilleTrie}>
<ActualitesProvider>
<ChatCredentialsProvider>
<ChatsProvider>
<CurrentConversationProvider>
<ShowRubriqueListeDeDiffusionProvider>
<ListeDeDiffusionSelectionneeProvider>
<AlerteProvider>
<ThemeProvider
defaultTheme={'neutral'}
themes={['neutral', 'darker']}
forcedTheme={theme}
>
{children}
</ThemeProvider>
</MobileViewportProvider>
</AlerteProvider>
</ListeDeDiffusionSelectionneeProvider>
</ShowRubriqueListeDeDiffusionProvider>
</CurrentConversationProvider>
</ChatsProvider>
</ChatCredentialsProvider>
</ActualitesProvider>
</PortefeuilleProvider>
</ConseillerProvider>
</AlerteProvider>
</ListeDeDiffusionSelectionneeProvider>
</ShowRubriqueListeDeDiffusionProvider>
</CurrentConversationProvider>
</ChatsProvider>
</ChatCredentialsProvider>
</ActualitesProvider>
</PortefeuilleProvider>
</ConseillerProvider>
</MobileViewportProvider>
)
}

0 comments on commit 1febc14

Please sign in to comment.