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";
|
"use client";
|
||||||
|
|
||||||
import { type ReactNode } from "react";
|
import { type ReactNode, useRef } from "react";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
|
||||||
@@ -17,8 +17,20 @@ export function MobileNav({
|
|||||||
closeLabel = "Close menu",
|
closeLabel = "Close menu",
|
||||||
brandLabel = "Atom",
|
brandLabel = "Atom",
|
||||||
}: MobileNavProps) {
|
}: 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 (
|
return (
|
||||||
<details className="group relative md:hidden">
|
<details
|
||||||
|
ref={detailsRef}
|
||||||
|
onClick={handleClick}
|
||||||
|
className="group relative md:hidden"
|
||||||
|
>
|
||||||
<summary
|
<summary
|
||||||
className="list-none cursor-pointer flex items-center justify-center w-11 h-11 rounded-xl shrink-0
|
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
|
[&::-webkit-details-marker]:hidden transition-colors duration-150
|
||||||
|
|||||||
Reference in new issue
Block a user