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 && ( + + )} + + ) : ( +
  • + - ▼ - - - {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 + +
  • + + + )}
    );