From f7d8ff506210b60b716d762108887af694b32ea2 Mon Sep 17 00:00:00 2001 From: lacatoire Date: Fri, 10 Apr 2026 11:08:39 +0200 Subject: [PATCH] fix --- src/components/layout/MobileMenu.tsx | 171 ++++++++++++++++----------- 1 file changed, 104 insertions(+), 67 deletions(-) diff --git a/src/components/layout/MobileMenu.tsx b/src/components/layout/MobileMenu.tsx index 9175133..52a60fd 100644 --- a/src/components/layout/MobileMenu.tsx +++ b/src/components/layout/MobileMenu.tsx @@ -1,6 +1,6 @@ "use client"; -import { useState } from "react"; +import { useState, useEffect, useCallback } from "react"; import Link from "next/link"; import { NavItem, isDropdown } from "@/types/navigation"; import { trackEvent } from "@/lib/tracking"; @@ -13,10 +13,26 @@ export default function MobileMenu({ items }: MobileMenuProps) { const [open, setOpen] = useState(false); const [expandedIndex, setExpandedIndex] = useState(null); + const closeMenu = useCallback(() => { + setOpen(false); + setExpandedIndex(null); + }, []); + const toggleDropdown = (index: number) => { setExpandedIndex(expandedIndex === index ? null : index); }; + useEffect(() => { + if (!open) return; + const handleKeyDown = (e: KeyboardEvent) => { + if (e.key === "Escape") { + closeMenu(); + } + }; + document.addEventListener("keydown", handleKeyDown); + return () => document.removeEventListener("keydown", handleKeyDown); + }, [open, closeMenu]); + return (
+ {expandedIndex === index && ( +
    + {item.items.map((link) => ( +
  • + + {link.label} + +
  • + ))} + {item.highlight && ( +
  • + + {item.highlight.label} + +
  • + )} +
+ )} + + ) : ( +
  • + - ▼ - - - {expandedIndex === index && ( -
      - {item.items.map((link) => ( -
    • - setOpen(false)} - > - {link.label} - -
    • - ))} -
    - )} -
  • - ) : ( -
  • - setOpen(false)} - > - {item.label} - -
  • - ), - )} -
  • - { trackEvent("cta_click", { cta_location: "header_mobile", cta_text: "Audit Symfony gratuit" }); setOpen(false); }} - > - Audit Symfony gratuit - -
  • -
  • - { trackEvent("cta_click", { cta_location: "header_mobile", cta_text: "Contact" }); setOpen(false); }} - > - Contact - -
  • - - + {item.label} + + + ), + )} +
  • + { trackEvent("cta_click", { cta_location: "header_mobile", cta_text: "Audit Symfony gratuit" }); closeMenu(); }} + > + Audit Symfony gratuit + +
  • +
  • + { trackEvent("cta_click", { cta_location: "header_mobile", cta_text: "Contact" }); closeMenu(); }} + > + Contact + +
  • + + + )}
    );