Skip to content

Commit

Permalink
Add handler to close sidebar on mobile when menu item clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchernchong committed Nov 2, 2024
1 parent 9485023 commit 304d111
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions components/AppSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
SidebarMenuSub,
SidebarMenuSubButton,
SidebarMenuSubItem,
useSidebar,
} from "@/components/ui/sidebar";

type NavItem = {
Expand All @@ -53,6 +54,7 @@ type Nav = {

export const AppSidebar = () => {
const pathname = usePathname();
const { setOpenMobile } = useSidebar();

return (
<Sidebar>
Expand Down Expand Up @@ -95,6 +97,7 @@ export const AppSidebar = () => {
<SidebarMenuSubButton
asChild
isActive={subItem.url === pathname}
onClick={() => setOpenMobile(false)}
>
<Link href={subItem.url}>
{subItem.icon && <subItem.icon />}
Expand Down

0 comments on commit 304d111

Please sign in to comment.