Skip to content

Commit df02db6

Browse files
fix: close nav dropdown after choosing item
1 parent 0f5a9f2 commit df02db6

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Diff for: src/features/Header/DropDownNavLinks.tsx

+12-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import { Button } from "@radix-ui/themes";
66
import dropDownIcon from "../../assets/dropdown_arrow.svg";
77
import { useAtomValue } from "jotai";
88
import { containerElAtom } from "../../atoms";
9-
import { PropsWithChildren } from "react";
9+
import { PropsWithChildren, useState } from "react";
1010

1111
export default function DropDownNavLinks({ children }: PropsWithChildren) {
1212
const containerEl = useAtomValue(containerElAtom);
13+
const [dropdownOpen, setDropdownOpen] = useState(false);
1314

1415
const location = useLocation();
1516
let route = "Overview";
@@ -20,7 +21,7 @@ export default function DropDownNavLinks({ children }: PropsWithChildren) {
2021
}
2122

2223
return (
23-
<DropdownMenu.Root>
24+
<DropdownMenu.Root open={dropdownOpen} onOpenChange={setDropdownOpen}>
2425
<DropdownMenu.Trigger asChild>
2526
{children || (
2627
<Button className={styles.button}>
@@ -30,10 +31,18 @@ export default function DropDownNavLinks({ children }: PropsWithChildren) {
3031
)}
3132
</DropdownMenu.Trigger>
3233
<DropdownMenu.Portal container={containerEl}>
33-
<DropdownMenu.Content className={styles.content} sideOffset={5}>
34+
<DropdownMenu.Content
35+
className={styles.content}
36+
sideOffset={5}
37+
onClick={() => setDropdownOpen(false)}
38+
>
3439
<DropdownMenu.Item className={styles.item}>
3540
<NavLink to="/" label="Overview" />
41+
</DropdownMenu.Item>
42+
<DropdownMenu.Item className={styles.item}>
3643
<NavLink to="/leaderSchedule" label="Leader Schedule" />
44+
</DropdownMenu.Item>
45+
<DropdownMenu.Item className={styles.item}>
3746
<NavLink to="/gossip" label="Gossip" />
3847
</DropdownMenu.Item>
3948
</DropdownMenu.Content>

0 commit comments

Comments
 (0)