Skip to content

Commit 9daa7a1

Browse files
committed
fix(ui): navbar not closing on mobile devices
1 parent d8dac5c commit 9daa7a1

File tree

11 files changed

+69
-78
lines changed

11 files changed

+69
-78
lines changed

.changeset/silent-pants-tickle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'mantine-analytics-dashboard': minor
3+
---
4+
5+
fix(ui): navbar not closing on mobile devices
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'mantine-analytics-dashboard': patch
3+
---
4+
5+
changed onboarding flow to landing -> signin -> dashboard, removed "auto" theme support now is light & dark only

app/apps/layout.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client';
22

33
import { AppShell, Container, rem, useMantineTheme } from '@mantine/core';
4-
import { ReactNode, useState } from 'react';
4+
import { ReactNode } from 'react';
55
import { useDisclosure, useMediaQuery } from '@mantine/hooks';
66
import AppMain from '@/components/AppMain';
77
import Navigation from '@/components/Navigation';
@@ -12,11 +12,8 @@ type Props = {
1212
children: ReactNode;
1313
};
1414

15-
function CalendarLayout({ children }: Props) {
15+
function AppsLayout({ children }: Props) {
1616
const theme = useMantineTheme();
17-
const [opened, setOpened] = useState(false);
18-
const [themeOpened, { open: themeOpen, close: themeClose }] =
19-
useDisclosure(false);
2017
const tablet_match = useMediaQuery('(max-width: 768px)');
2118
const [mobileOpened, { toggle: toggleMobile }] = useDisclosure();
2219
const [desktopOpened, { toggle: toggleDesktop }] = useDisclosure(true);
@@ -42,8 +39,6 @@ function CalendarLayout({ children }: Props) {
4239
>
4340
<Container fluid py="sm" px="lg">
4441
<HeaderNav
45-
opened={opened}
46-
handleOpen={() => setOpened((o) => !o)}
4742
desktopOpened={desktopOpened}
4843
mobileOpened={mobileOpened}
4944
toggleDesktop={toggleDesktop}
@@ -52,7 +47,7 @@ function CalendarLayout({ children }: Props) {
5247
</Container>
5348
</AppShell.Header>
5449
<AppShell.Navbar>
55-
<Navigation onClose={() => setOpened(false)} />
50+
<Navigation onClose={toggleMobile} />
5651
</AppShell.Navbar>
5752
<AppShell.Main>
5853
<AppMain>{children}</AppMain>
@@ -66,4 +61,4 @@ function CalendarLayout({ children }: Props) {
6661
);
6762
}
6863

69-
export default CalendarLayout;
64+
export default AppsLayout;

app/authentication/auth0/layout.tsx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
'use client';
22

3-
import { ReactNode, useState } from 'react';
4-
import { Providers } from '@/providers/session';
53
import { AppShell, Container, rem, useMantineTheme } from '@mantine/core';
6-
import HeaderNav from '@/components/HeaderNav';
7-
import Navigation from '@/components/Navigation';
4+
import { ReactNode, useState } from 'react';
5+
import { useDisclosure, useMediaQuery } from '@mantine/hooks';
86
import AppMain from '@/components/AppMain';
7+
import Navigation from '@/components/Navigation';
8+
import HeaderNav from '@/components/HeaderNav';
99
import FooterNav from '@/components/FooterNav';
10-
import { useDisclosure, useMediaQuery } from '@mantine/hooks';
10+
import { Providers } from '@/providers/session';
1111

12-
type Auth0LayoutProps = {
12+
type Props = {
1313
children: ReactNode;
1414
};
1515

16-
export default function Auth0Layout({ children }: Auth0LayoutProps) {
16+
function Auth0Layout({ children }: Props) {
1717
const theme = useMantineTheme();
18-
const [opened, setOpened] = useState(false);
19-
const [themeOpened, { open: themeOpen, close: themeClose }] =
20-
useDisclosure(false);
2118
const tablet_match = useMediaQuery('(max-width: 768px)');
2219
const [mobileOpened, { toggle: toggleMobile }] = useDisclosure();
2320
const [desktopOpened, { toggle: toggleDesktop }] = useDisclosure(true);
@@ -43,8 +40,6 @@ export default function Auth0Layout({ children }: Auth0LayoutProps) {
4340
>
4441
<Container fluid py="sm" px="lg">
4542
<HeaderNav
46-
opened={opened}
47-
handleOpen={() => setOpened((o) => !o)}
4843
desktopOpened={desktopOpened}
4944
mobileOpened={mobileOpened}
5045
toggleDesktop={toggleDesktop}
@@ -53,7 +48,7 @@ export default function Auth0Layout({ children }: Auth0LayoutProps) {
5348
</Container>
5449
</AppShell.Header>
5550
<AppShell.Navbar>
56-
<Navigation onClose={() => setOpened(false)} />
51+
<Navigation onClose={toggleMobile} />
5752
</AppShell.Navbar>
5853
<AppShell.Main>
5954
<AppMain>
@@ -68,3 +63,5 @@ export default function Auth0Layout({ children }: Auth0LayoutProps) {
6863
</AppShell>
6964
);
7065
}
66+
67+
export default Auth0Layout;

app/authentication/clerk/layout.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ import AppMain from '@/components/AppMain';
77
import Navigation from '@/components/Navigation';
88
import HeaderNav from '@/components/HeaderNav';
99
import FooterNav from '@/components/FooterNav';
10+
import { Providers } from '@/providers/session';
1011

1112
type Props = {
1213
children: ReactNode;
1314
};
1415

1516
function ClerkLayout({ children }: Props) {
1617
const theme = useMantineTheme();
17-
const [opened, setOpened] = useState(false);
18-
const [themeOpened, { open: themeOpen, close: themeClose }] =
19-
useDisclosure(false);
2018
const tablet_match = useMediaQuery('(max-width: 768px)');
2119
const [mobileOpened, { toggle: toggleMobile }] = useDisclosure();
2220
const [desktopOpened, { toggle: toggleDesktop }] = useDisclosure(true);
@@ -42,8 +40,6 @@ function ClerkLayout({ children }: Props) {
4240
>
4341
<Container fluid py="sm" px="lg">
4442
<HeaderNav
45-
opened={opened}
46-
handleOpen={() => setOpened((o) => !o)}
4743
desktopOpened={desktopOpened}
4844
mobileOpened={mobileOpened}
4945
toggleDesktop={toggleDesktop}
@@ -52,10 +48,12 @@ function ClerkLayout({ children }: Props) {
5248
</Container>
5349
</AppShell.Header>
5450
<AppShell.Navbar>
55-
<Navigation onClose={() => setOpened(false)} />
51+
<Navigation onClose={toggleMobile} />
5652
</AppShell.Navbar>
5753
<AppShell.Main>
58-
<AppMain>{children}</AppMain>
54+
<AppMain>
55+
<Providers>{children}</Providers>
56+
</AppMain>
5957
</AppShell.Main>
6058
<AppShell.Footer p="md">
6159
<Container fluid px="lg">

app/dashboard/layout.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ type Props = {
1212
children: ReactNode;
1313
};
1414

15-
function CalendarLayout({ children }: Props) {
15+
function DashboardLayout({ children }: Props) {
1616
const theme = useMantineTheme();
17-
const [opened, setOpened] = useState(false);
18-
const [themeOpened, { open: themeOpen, close: themeClose }] =
19-
useDisclosure(false);
2017
const tablet_match = useMediaQuery('(max-width: 768px)');
2118
const [mobileOpened, { toggle: toggleMobile }] = useDisclosure();
2219
const [desktopOpened, { toggle: toggleDesktop }] = useDisclosure(true);
@@ -42,8 +39,6 @@ function CalendarLayout({ children }: Props) {
4239
>
4340
<Container fluid py="sm" px="lg">
4441
<HeaderNav
45-
opened={opened}
46-
handleOpen={() => setOpened((o) => !o)}
4742
desktopOpened={desktopOpened}
4843
mobileOpened={mobileOpened}
4944
toggleDesktop={toggleDesktop}
@@ -52,7 +47,7 @@ function CalendarLayout({ children }: Props) {
5247
</Container>
5348
</AppShell.Header>
5449
<AppShell.Navbar>
55-
<Navigation onClose={() => setOpened(false)} />
50+
<Navigation onClose={toggleMobile} />
5651
</AppShell.Navbar>
5752
<AppShell.Main>
5853
<AppMain>{children}</AppMain>
@@ -66,4 +61,4 @@ function CalendarLayout({ children }: Props) {
6661
);
6762
}
6863

69-
export default CalendarLayout;
64+
export default DashboardLayout;

app/page.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ import {
2828
useMantineTheme,
2929
} from '@mantine/core';
3030
import Link from 'next/link';
31-
import { PATH_APPS, PATH_DASHBOARD, PATH_DOCS, PATH_GITHUB } from '@/routes';
31+
import {
32+
PATH_APPS,
33+
PATH_AUTH,
34+
PATH_DASHBOARD,
35+
PATH_DOCS,
36+
PATH_GITHUB,
37+
} from '@/routes';
3238
import {
3339
IconAdjustmentsHorizontal,
3440
IconApps,
@@ -297,7 +303,7 @@ export default function Home() {
297303
<Group my="lg">
298304
<Button
299305
component={Link}
300-
href={PATH_DASHBOARD.default}
306+
href={PATH_AUTH.signin}
301307
size="md"
302308
leftSection={<IconPlayerPlay size={18} />}
303309
>

app/pages/layout.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ type Props = {
1212
children: ReactNode;
1313
};
1414

15-
function CalendarLayout({ children }: Props) {
15+
function PagesLayout({ children }: Props) {
1616
const theme = useMantineTheme();
17-
const [opened, setOpened] = useState(false);
18-
const [themeOpened, { open: themeOpen, close: themeClose }] =
19-
useDisclosure(false);
2017
const tablet_match = useMediaQuery('(max-width: 768px)');
2118
const [mobileOpened, { toggle: toggleMobile }] = useDisclosure();
2219
const [desktopOpened, { toggle: toggleDesktop }] = useDisclosure(true);
@@ -42,8 +39,6 @@ function CalendarLayout({ children }: Props) {
4239
>
4340
<Container fluid py="sm" px="lg">
4441
<HeaderNav
45-
opened={opened}
46-
handleOpen={() => setOpened((o) => !o)}
4742
desktopOpened={desktopOpened}
4843
mobileOpened={mobileOpened}
4944
toggleDesktop={toggleDesktop}
@@ -52,7 +47,7 @@ function CalendarLayout({ children }: Props) {
5247
</Container>
5348
</AppShell.Header>
5449
<AppShell.Navbar>
55-
<Navigation onClose={() => setOpened(false)} />
50+
<Navigation onClose={toggleMobile} />
5651
</AppShell.Navbar>
5752
<AppShell.Main>
5853
<AppMain>{children}</AppMain>
@@ -66,4 +61,4 @@ function CalendarLayout({ children }: Props) {
6661
);
6762
}
6863

69-
export default CalendarLayout;
64+
export default PagesLayout;

components/HeaderNav/HeaderNav.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,23 +129,14 @@ const NOTIFICATIONS = [
129129
];
130130

131131
type HeaderNavProps = {
132-
opened?: boolean;
133-
handleOpen?: () => void;
134132
mobileOpened?: boolean;
135133
toggleMobile?: () => void;
136134
desktopOpened?: boolean;
137135
toggleDesktop?: () => void;
138136
};
139137

140138
const HeaderNav = (props: HeaderNavProps) => {
141-
const {
142-
handleOpen,
143-
opened,
144-
desktopOpened,
145-
toggleDesktop,
146-
toggleMobile,
147-
mobileOpened,
148-
} = props;
139+
const { desktopOpened, toggleDesktop, toggleMobile, mobileOpened } = props;
149140
const theme = useMantineTheme();
150141
const { setColorScheme, colorScheme } = useMantineColorScheme();
151142
const laptop_match = useMediaQuery('(max-width: 992px)');

components/Navigation/Links/Links.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import {useEffect, useState} from 'react';
2-
import {Box, Collapse, Group, Text, UnstyledButton,} from '@mantine/core';
3-
import {IconChevronRight} from '@tabler/icons-react';
4-
import Link from 'next/link';
5-
import {usePathname, useRouter} from 'next/navigation';
1+
import { useEffect, useState } from 'react';
2+
import { Box, Collapse, Group, Text, UnstyledButton } from '@mantine/core';
3+
import { IconChevronRight } from '@tabler/icons-react';
4+
import { usePathname, useRouter } from 'next/navigation';
65
import * as _ from 'lodash';
76
import classes from './Links.module.css';
87

@@ -15,6 +14,7 @@ interface LinksGroupProps {
1514
label: string;
1615
link: string;
1716
}[];
17+
closeSidebar: () => void;
1818
}
1919

2020
export function LinksGroup(props: LinksGroupProps) {
@@ -24,6 +24,7 @@ export function LinksGroup(props: LinksGroupProps) {
2424
initiallyOpened,
2525
link,
2626
links,
27+
closeSidebar,
2728
} = props;
2829
const router = useRouter();
2930
const pathname = usePathname();
@@ -34,9 +35,12 @@ export function LinksGroup(props: LinksGroupProps) {
3435

3536
const items = (hasLinks ? links : []).map((link) => (
3637
<Text
37-
component={Link}
38+
component="button"
3839
className={classes.link}
39-
href={link.link}
40+
onClick={() => {
41+
router.push(link.link);
42+
closeSidebar();
43+
}}
4044
key={link.label}
4145
data-active={link.link.toLowerCase() === pathname || undefined}
4246
>
@@ -56,13 +60,14 @@ export function LinksGroup(props: LinksGroupProps) {
5660
onClick={() => {
5761
setOpened((o) => !o);
5862
link && router.push(link || '#');
63+
closeSidebar();
5964
}}
6065
className={classes.control}
6166
data-active={opened || undefined}
6267
>
6368
<Group justify="space-between" gap={0}>
64-
<Box style={{display: 'flex', alignItems: 'center'}}>
65-
<Icon size={18}/>
69+
<Box style={{ display: 'flex', alignItems: 'center' }}>
70+
<Icon size={18} />
6671
<Box ml="md">{label}</Box>
6772
</Box>
6873
{hasLinks && (

0 commit comments

Comments
 (0)