Skip to content

Commit 7dd1d45

Browse files
committed
feat(ep/layout): implement responsive navigation menu
1 parent 6c53b62 commit 7dd1d45

2 files changed

Lines changed: 55 additions & 40 deletions

File tree

client/src/boards/european-projects/components/layouts/global-layout.tsx

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Container } from "@dataesr/dsfr-plus";
2-
import { useEffect } from "react";
2+
import { useEffect, useState } from "react";
33
import { Link, Outlet, useLocation, useSearchParams } from "react-router-dom";
44

55
import CountrySelector from "../../../../components/country-selector/selector";
@@ -12,6 +12,7 @@ import "../../colors.scss";
1212
export default function GlobalLayout() {
1313
const { pathname } = useLocation();
1414
const [searchParams, setSearchParams] = useSearchParams();
15+
const [isMenuOpen, setIsMenuOpen] = useState(false);
1516
const currentLang = searchParams.get("language") || "fr";
1617
const filtersParams = searchParams.toString();
1718

@@ -30,6 +31,10 @@ export default function GlobalLayout() {
3031
}
3132
}, [searchParams, setSearchParams]);
3233

34+
useEffect(() => {
35+
setIsMenuOpen(false);
36+
}, [pathname]);
37+
3338
if (!pathname) return null;
3439
const is = (str: string): boolean => pathname?.startsWith(str);
3540

@@ -61,12 +66,14 @@ export default function GlobalLayout() {
6166
</div>
6267
<div className="fr-header__navbar">
6368
<button
64-
data-fr-opened="false"
65-
aria-controls="modal-header"
69+
data-fr-opened={isMenuOpen ? "true" : "false"}
70+
aria-controls="main-navigation"
71+
aria-expanded={isMenuOpen}
6672
title="Menu"
6773
type="button"
6874
id="button-header"
6975
className="fr-btn--menu fr-btn"
76+
onClick={() => setIsMenuOpen((open) => !open)}
7077
>
7178
Menu
7279
</button>
@@ -77,67 +84,37 @@ export default function GlobalLayout() {
7784
</div>
7885
</div>
7986
</header>
80-
<nav className="ep-sticky-nav fr-nav" role="navigation" aria-label="Menu principal">
87+
<nav id="main-navigation" className={`ep-sticky-nav fr-nav${isMenuOpen ? " ep-nav-open" : ""}`} role="navigation" aria-label="Menu principal">
8188
<Container>
8289
<ul className="fr-nav__list">
8390
<li className="fr-nav__item">
84-
<Link
85-
to="/european-projects/accueil"
86-
target="_self"
87-
{...(pathname === "/european-projects/accueil" && { "aria-current": "page" })}
88-
className="fr-nav__link"
89-
>
91+
<Link to="/european-projects/accueil" target="_self" {...(pathname === "/european-projects/accueil" && { "aria-current": "page" })} className="fr-nav__link">
9092
<span className="fr-icon-home-4-line fr-mr-1w" aria-hidden="true" />
9193
{getI18nLabel("home")}
9294
</Link>
9395
</li>
9496
<li className="fr-nav__item">
95-
<Link
96-
to={`/european-projects/horizon-europe?section=synthesis&${filtersParams}`}
97-
target="_self"
98-
{...(is("/european-projects/horizon-europe") && { "aria-current": "page" })}
99-
className="fr-nav__link"
100-
>
97+
<Link to={`/european-projects/horizon-europe?section=synthesis&${filtersParams}`} target="_self" {...(is("/european-projects/horizon-europe") && { "aria-current": "page" })} className="fr-nav__link">
10198
{getI18nLabel("he")}
10299
</Link>
103100
</li>
104101
<li className="fr-nav__item">
105-
<Link
106-
to={`/european-projects/msca?${filtersParams}`}
107-
target="_self"
108-
{...(is("/european-projects/msca") && { "aria-current": "page" })}
109-
className="fr-nav__link"
110-
>
102+
<Link to={`/european-projects/msca?${filtersParams}`} target="_self" {...(is("/european-projects/msca") && { "aria-current": "page" })} className="fr-nav__link">
111103
Focus MSCA
112104
</Link>
113105
</li>
114106
<li className="fr-nav__item">
115-
<Link
116-
to={`/european-projects/erc?${filtersParams}`}
117-
target="_self"
118-
{...(is("/european-projects/erc") && { "aria-current": "page" })}
119-
className="fr-nav__link"
120-
>
107+
<Link to={`/european-projects/erc?${filtersParams}`} target="_self" {...(is("/european-projects/erc") && { "aria-current": "page" })} className="fr-nav__link">
121108
Focus ERC
122109
</Link>
123110
</li>
124111
<li className="fr-nav__item">
125-
<Link
126-
to="/european-projects/evolution-pcri"
127-
target="_self"
128-
{...(is("/european-projects/evolution-pcri") && { "aria-current": "page" })}
129-
className="fr-nav__link"
130-
>
112+
<Link to="/european-projects/evolution-pcri" target="_self" {...(is("/european-projects/evolution-pcri") && { "aria-current": "page" })} className="fr-nav__link">
131113
{getI18nLabel("evolutionPcri")}
132114
</Link>
133115
</li>
134116
<li>
135-
<Link
136-
to={`/european-projects/entities?${filtersParams}`}
137-
target="_self"
138-
{...(is("/european-projects/entities") && { "aria-current": "page" })}
139-
className="fr-nav__link"
140-
>
117+
<Link to={`/european-projects/entities?${filtersParams}`} target="_self" {...(is("/european-projects/entities") && { "aria-current": "page" })} className="fr-nav__link">
141118
{getI18nLabel("entities")}
142119
</Link>
143120
</li>

client/src/boards/european-projects/components/styles.scss

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,44 @@
203203
}
204204
}
205205

206+
@media (max-width: 991px) {
207+
.ep-sticky-nav {
208+
position: fixed;
209+
top: 5.5rem;
210+
left: 0;
211+
right: 0;
212+
width: 100%;
213+
background-color: var(--background-default-grey-hover);
214+
max-height: 0;
215+
overflow: hidden;
216+
opacity: 0;
217+
visibility: hidden;
218+
transition: max-height 0.3s ease, opacity 0.3s ease, visibility 0.3s ease;
219+
z-index: 1003;
220+
}
221+
222+
.ep-sticky-nav.ep-nav-open {
223+
max-height: calc(100vh - 5.5rem);
224+
opacity: 1;
225+
visibility: visible;
226+
}
227+
228+
.ep-sticky-nav .fr-nav__list {
229+
flex-direction: column;
230+
gap: 0;
231+
}
232+
233+
.ep-sticky-nav .fr-nav__item {
234+
margin: 0;
235+
}
236+
237+
.ep-sticky-nav .fr-nav__link {
238+
width: 100%;
239+
padding: 0.75rem 1rem;
240+
border-bottom: 1px solid var(--border-default-grey);
241+
}
242+
}
243+
206244
// Fix pour que le dropdown du sélecteur de langue passe au-dessus du menu principal
207245
.fr-header {
208246
z-index: 1002 !important;

0 commit comments

Comments
 (0)