mirror of
https://github.com/elisiariocouto/leggen.git
synced 2025-12-14 10:52:18 +00:00
fix(frontend): Close mobile sidebar on navigation item click
Co-authored-by: elisiariocouto <818914+elisiariocouto@users.noreply.github.com>
This commit is contained in:
committed by
Elisiário Couto
parent
ff9bccc0e9
commit
dd24a0e0d3
@@ -27,6 +27,7 @@ import {
|
|||||||
SidebarGroup,
|
SidebarGroup,
|
||||||
SidebarGroupContent,
|
SidebarGroupContent,
|
||||||
SidebarGroupLabel,
|
SidebarGroupLabel,
|
||||||
|
useSidebar,
|
||||||
} from "./ui/sidebar";
|
} from "./ui/sidebar";
|
||||||
|
|
||||||
const navigation = [
|
const navigation = [
|
||||||
@@ -39,6 +40,7 @@ const navigation = [
|
|||||||
export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
|
export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const [accountsExpanded, setAccountsExpanded] = useState(false);
|
const [accountsExpanded, setAccountsExpanded] = useState(false);
|
||||||
|
const { isMobile, setOpenMobile } = useSidebar();
|
||||||
|
|
||||||
const { data: accounts } = useQuery<Account[]>({
|
const { data: accounts } = useQuery<Account[]>({
|
||||||
queryKey: ["accounts"],
|
queryKey: ["accounts"],
|
||||||
@@ -51,6 +53,13 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
|
|||||||
return sum + primaryBalance;
|
return sum + primaryBalance;
|
||||||
}, 0) || 0;
|
}, 0) || 0;
|
||||||
|
|
||||||
|
// Handler to close mobile sidebar when navigation item is clicked
|
||||||
|
const handleNavigationClick = () => {
|
||||||
|
if (isMobile) {
|
||||||
|
setOpenMobile(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Sidebar collapsible="icon" className="pt-safe-top pl-safe-left" {...props}>
|
<Sidebar collapsible="icon" className="pt-safe-top pl-safe-left" {...props}>
|
||||||
<SidebarHeader>
|
<SidebarHeader>
|
||||||
@@ -60,7 +69,7 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
|
|||||||
asChild
|
asChild
|
||||||
className="data-[slot=sidebar-menu-button]:!p-1.5"
|
className="data-[slot=sidebar-menu-button]:!p-1.5"
|
||||||
>
|
>
|
||||||
<Link to="/" className="flex items-center space-x-2">
|
<Link to="/" className="flex items-center space-x-2" onClick={handleNavigationClick}>
|
||||||
<Logo size={24} />
|
<Logo size={24} />
|
||||||
<span className="text-base font-semibold">Leggen</span>
|
<span className="text-base font-semibold">Leggen</span>
|
||||||
</Link>
|
</Link>
|
||||||
@@ -80,7 +89,7 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
|
|||||||
tooltip={item.name}
|
tooltip={item.name}
|
||||||
isActive={location.pathname === item.to}
|
isActive={location.pathname === item.to}
|
||||||
>
|
>
|
||||||
<Link to={item.to}>
|
<Link to={item.to} onClick={handleNavigationClick}>
|
||||||
<item.icon className="h-5 w-5" />
|
<item.icon className="h-5 w-5" />
|
||||||
<span>{item.name}</span>
|
<span>{item.name}</span>
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
Reference in New Issue
Block a user