AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Mobile Hamburger Menu Stays Open When Search Modal Opens

On mobile/tablet, opening the search modal while the hamburger menu is open leaves the menu overlapping the search interface, causing a UX issue. The menu should automatically close when search is triggered.

mediumConfidence 78%Next.js

Origin Analysis

The hamburger menu state and search modal state are managed independently; the search open handler does not trigger closure of the mobile navigation menu, leading to both UI elements being visible simultaneously.
1. Open nextjs.org/docs on a mobile viewport. 2. Tap the hamburger menu icon to open mobile navigation. 3. Tap the search icon while the menu is open. 4. Observe that the search modal opens but the hamburger menu remains open and overlaps it.

Fixing Code Block

const [menuOpen, setMenuOpen] = useState(false); const [searchOpen, setSearchOpen] = useState(false); const handleSearchClick = () => { setMenuOpen(false); // Close hamburger menu before opening search setSearchOpen(true); }; // Ensure the search button uses this handler: <button onClick={handleSearchClick}>Search</button>
The fix ensures that when the search icon is clicked, the menu state is explicitly set to false before or alongside opening the search modal. This eliminates the overlap by synchronizing the two UI states.

Edge Case Audit

This change may accidentally re-open the menu if other components also control menuOpen and searchOpen without coordinating. Ensure all search invocation paths (e.g., keyboard shortcut, CMD+K) also close the menu. Adding a regression test for mobile menu and search interaction is recommended. Rollback is straightforward by reverting the state update line.

Ecosystem Topology