import { FormEvent, useEffect, useRef, useState } from 'react' import { NavLink, useLocation, useNavigate } from 'react-router-dom' import { IconClose, IconGrid, IconHome, IconSearch, IconStore } from './Icons' /** * Mobile bottom tab bar (<768px) — Accueil, Produits, Boutiques, Recherche. * "Recherche" opens a full-screen search overlay with an autofocused input. */ export default function BottomNav() { const [searchOpen, setSearchOpen] = useState(false) const [query, setQuery] = useState('') const inputRef = useRef(null) const navigate = useNavigate() const location = useLocation() // Close the overlay on navigation. useEffect(() => { setSearchOpen(false) }, [location.pathname, location.search]) // Autofocus + scroll lock while the overlay is open. useEffect(() => { if (!searchOpen) return document.body.style.overflow = 'hidden' const t = window.setTimeout(() => inputRef.current?.focus(), 60) const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') setSearchOpen(false) } window.addEventListener('keydown', onKey) return () => { document.body.style.overflow = '' window.clearTimeout(t) window.removeEventListener('keydown', onKey) } }, [searchOpen]) function onSubmit(e: FormEvent) { e.preventDefault() const q = query.trim() setSearchOpen(false) setQuery('') navigate(q ? `/produits?q=${encodeURIComponent(q)}` : '/produits') } return ( <> {searchOpen && (
setQuery(e.target.value)} placeholder="Rechercher un produit québécois…" aria-label="Rechercher" enterKeyHint="search" />

Produits fabriqués, conçus et vendus au Québec.

)} ) }