Skip to content

Commit

Permalink
Close nav drawer on navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscariremma committed Dec 8, 2024
1 parent 767b02b commit cb93590
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/components/Header/NavDrawer/NavDrawer.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
'use client';
import { useRef, useEffect } from 'react';
import { usePathname, useSearchParams } from 'next/navigation';
import styles from './NavDrawer.module.scss';
import { FaBars } from 'react-icons/fa6';

const NavDrawer = ({ children }: { children: React.ReactNode }) => {
const pathname = usePathname();
const searchParams = useSearchParams();
const inputRef = useRef<HTMLInputElement>(null);

const handleClose = () => {
if (inputRef.current) {
inputRef.current.checked = false;
}
};

useEffect(() => {
handleClose();
}, [pathname, searchParams]);

return (
<div>
<label htmlFor="drawer-toggle">
<FaBars className={styles.toggle} />
</label>
<input
ref={inputRef}
className={styles.checkbox}
type="checkbox"
id="drawer-toggle"
Expand Down

0 comments on commit cb93590

Please sign in to comment.