Close mobile nav menu when a link inside is tapped
Local Build and Deploy / deploy (push) Successful in 58s
Local Build and Deploy / deploy (push) Successful in 58s
This commit is contained in:
1 parent
af1b18d866
commit
db1875b40b
1 file changed
+14
-2
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { type ReactNode } from "react";
|
||||
import { type ReactNode, useRef } from "react";
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
|
||||
@@ -17,8 +17,20 @@ export function MobileNav({
|
||||
closeLabel = "Close menu",
|
||||
brandLabel = "Atom",
|
||||
}: MobileNavProps) {
|
||||
const detailsRef = useRef<HTMLDetailsElement>(null);
|
||||
|
||||
const handleClick = (e: React.MouseEvent) => {
|
||||
if ((e.target as HTMLElement).closest("a") && detailsRef.current) {
|
||||
detailsRef.current.open = false;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<details className="group relative md:hidden">
|
||||
<details
|
||||
ref={detailsRef}
|
||||
onClick={handleClick}
|
||||
className="group relative md:hidden"
|
||||
>
|
||||
<summary
|
||||
className="list-none cursor-pointer flex items-center justify-center w-11 h-11 rounded-xl shrink-0
|
||||
[&::-webkit-details-marker]:hidden transition-colors duration-150
|
||||
|
||||
Reference in new issue
Block a user