Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Refix mobile menu closing when link is clicked #3915

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/src/components/landing/ToolpadDashboardLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Router>(() => {
return {
Expand Down Expand Up @@ -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<Router>(() => {
return {
Expand Down
18 changes: 14 additions & 4 deletions packages/toolpad-core/src/DashboardLayout/DashboardLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ interface DashboardSidebarSubNavigationProps {
subNavigation: Navigation;
basePath?: string;
depth?: number;
onSidebarItemClick?: (item: NavigationPageItem) => void;
onSidebarLinkClick?: (item: NavigationPageItem) => void;
validatedItemIds: Set<string>;
uniqueItemPaths: Set<string>;
}
Expand All @@ -157,7 +157,7 @@ function DashboardSidebarSubNavigation({
subNavigation,
basePath = '',
depth = 0,
onSidebarItemClick,
onSidebarLinkClick,
validatedItemIds,
uniqueItemPaths,
}: DashboardSidebarSubNavigationProps) {
Expand All @@ -183,6 +183,15 @@ function DashboardSidebarSubNavigation({
initialExpandedSidebarItemIds,
);

const handleLinkClick = React.useCallback(
(item: NavigationPageItem) => () => {
if (onSidebarLinkClick) {
onSidebarLinkClick(item);
}
},
[onSidebarLinkClick],
);

const handleOpenFolderClick = React.useCallback(
(itemId: string) => () => {
setExpandedSidebarItemIds((previousValue) =>
Expand Down Expand Up @@ -253,6 +262,7 @@ function DashboardSidebarSubNavigation({
: {
LinkComponent: Link,
href: navigationItemFullPath,
onClick: handleLinkClick(navigationItem),
})}
>
{navigationItem.icon ? (
Expand Down Expand Up @@ -298,7 +308,7 @@ function DashboardSidebarSubNavigation({
subNavigation={navigationItem.children}
basePath={navigationItemFullPath}
depth={depth + 1}
onSidebarItemClick={onSidebarItemClick}
onSidebarLinkClick={onSidebarLinkClick}
validatedItemIds={validatedItemIds}
uniqueItemPaths={uniqueItemPaths}
/>
Expand Down Expand Up @@ -371,7 +381,7 @@ function DashboardLayout(props: DashboardLayoutProps) {
<Box component="nav" sx={{ overflow: 'auto', pt: navigation[0]?.kind === 'header' ? 0 : 2 }}>
<DashboardSidebarSubNavigation
subNavigation={navigation}
onSidebarItemClick={handleNavigationItemClick}
onSidebarLinkClick={handleNavigationItemClick}
validatedItemIds={validatedItemIdsRef.current}
uniqueItemPaths={uniqueItemPathsRef.current}
/>
Expand Down
Loading