From 952ab6e419492e81de9c785dcdba7b9dbe528ef6 Mon Sep 17 00:00:00 2001 From: Pedro Ferreira <10789765+apedroferreira@users.noreply.github.com> Date: Fri, 9 Aug 2024 14:14:13 +0100 Subject: [PATCH 1/2] Refix mobile menu items --- .../landing/ToolpadDashboardLayout.tsx | 4 ++-- .../src/DashboardLayout/DashboardLayout.tsx | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/docs/src/components/landing/ToolpadDashboardLayout.tsx b/docs/src/components/landing/ToolpadDashboardLayout.tsx index b5bc4a76368..4752c525208 100644 --- a/docs/src/components/landing/ToolpadDashboardLayout.tsx +++ b/docs/src/components/landing/ToolpadDashboardLayout.tsx @@ -65,7 +65,7 @@ const NAVIGATION: Navigation = [ function DashboardLayoutBasic(props: DemoProps) { const { window } = props; - const [pathname, setPathname] = React.useState('/page'); + const [pathname, setPathname] = React.useState('/dashboard'); const router = React.useMemo(() => { return { @@ -159,7 +159,7 @@ const PlaceHolder = styled('div')<{ height: number }>(({ theme, height }) => ({ function DashboardLayoutBasic(props: DemoProps) { const { window } = props; - const [pathname, setPathname] = React.useState('/page'); + const [pathname, setPathname] = React.useState('/dashboard'); const router = React.useMemo(() => { return { diff --git a/packages/toolpad-core/src/DashboardLayout/DashboardLayout.tsx b/packages/toolpad-core/src/DashboardLayout/DashboardLayout.tsx index a66a98fc260..4e499e5001a 100644 --- a/packages/toolpad-core/src/DashboardLayout/DashboardLayout.tsx +++ b/packages/toolpad-core/src/DashboardLayout/DashboardLayout.tsx @@ -148,7 +148,7 @@ interface DashboardSidebarSubNavigationProps { subNavigation: Navigation; basePath?: string; depth?: number; - onSidebarItemClick?: (item: NavigationPageItem) => void; + onSidebarLinkClick?: (item: NavigationPageItem) => void; validatedItemIds: Set; uniqueItemPaths: Set; } @@ -157,7 +157,7 @@ function DashboardSidebarSubNavigation({ subNavigation, basePath = '', depth = 0, - onSidebarItemClick, + onSidebarLinkClick, validatedItemIds, uniqueItemPaths, }: DashboardSidebarSubNavigationProps) { @@ -183,6 +183,15 @@ function DashboardSidebarSubNavigation({ initialExpandedSidebarItemIds, ); + const handleNavigationLinkClick = React.useCallback( + (item: NavigationPageItem) => () => { + if (onSidebarLinkClick) { + onSidebarLinkClick(item); + } + }, + [onSidebarLinkClick], + ); + const handleOpenFolderClick = React.useCallback( (itemId: string) => () => { setExpandedSidebarItemIds((previousValue) => @@ -253,6 +262,7 @@ function DashboardSidebarSubNavigation({ : { LinkComponent: Link, href: navigationItemFullPath, + onClick: handleNavigationLinkClick(navigationItem), })} > {navigationItem.icon ? ( @@ -298,7 +308,7 @@ function DashboardSidebarSubNavigation({ subNavigation={navigationItem.children} basePath={navigationItemFullPath} depth={depth + 1} - onSidebarItemClick={onSidebarItemClick} + onSidebarLinkClick={onSidebarLinkClick} validatedItemIds={validatedItemIds} uniqueItemPaths={uniqueItemPaths} /> @@ -371,7 +381,7 @@ function DashboardLayout(props: DashboardLayoutProps) { From f801983c9747e8966d1a1fff99103e2b1a47eb43 Mon Sep 17 00:00:00 2001 From: Pedro Ferreira <10789765+apedroferreira@users.noreply.github.com> Date: Fri, 9 Aug 2024 14:17:43 +0100 Subject: [PATCH 2/2] Shorter name to match the other one --- packages/toolpad-core/src/DashboardLayout/DashboardLayout.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/toolpad-core/src/DashboardLayout/DashboardLayout.tsx b/packages/toolpad-core/src/DashboardLayout/DashboardLayout.tsx index 4e499e5001a..f6207ad11fe 100644 --- a/packages/toolpad-core/src/DashboardLayout/DashboardLayout.tsx +++ b/packages/toolpad-core/src/DashboardLayout/DashboardLayout.tsx @@ -183,7 +183,7 @@ function DashboardSidebarSubNavigation({ initialExpandedSidebarItemIds, ); - const handleNavigationLinkClick = React.useCallback( + const handleLinkClick = React.useCallback( (item: NavigationPageItem) => () => { if (onSidebarLinkClick) { onSidebarLinkClick(item); @@ -262,7 +262,7 @@ function DashboardSidebarSubNavigation({ : { LinkComponent: Link, href: navigationItemFullPath, - onClick: handleNavigationLinkClick(navigationItem), + onClick: handleLinkClick(navigationItem), })} > {navigationItem.icon ? (