Skip to content

Commit

Permalink
Merge pull request #24 from takeokunn/auto-close-navbar-on-mobile
Browse files Browse the repository at this point in the history
モバイルのとき、選択後に Navbar を自動的に閉じる
  • Loading branch information
tomoya authored Oct 3, 2024
2 parents c647150 + adb4ce5 commit c03f6cd
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/web/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ import {
rem,
} from "@mantine/core";
import "@mantine/core/styles.css";
import { useDisclosure, useHeadroom } from "@mantine/hooks";
import { useDisclosure, useHeadroom, useMediaQuery } from "@mantine/hooks";
import { useAwesomeYasunori } from "./hooks/use-awesome-yasunori";

export function Layout({ children }: { children: React.ReactNode }) {
const { data } = useAwesomeYasunori();
const isMobile = useMediaQuery("(max-width: 767px)");
const pinned = useHeadroom({ fixedAt: 120 });
const [opened, { toggle }] = useDisclosure();
const [opened, { toggle, close }] = useDisclosure();
const navigate = useNavigate();
return (
<html lang="ja">
Expand Down Expand Up @@ -65,7 +66,13 @@ export function Layout({ children }: { children: React.ReactNode }) {
{data?.map((d) => (
<NavLink
key={d.id}
onClick={() => navigate(`#${d.id}`, { replace: true })}
onClick={() => {
navigate(`#${d.id}`, { replace: true });
// モバイルのときは移動後にサイドバーを閉じる
if (isMobile) {
close();
}
}}
label={
<Group gap="xs">
<Text>{`${d.title}`}</Text>
Expand Down

0 comments on commit c03f6cd

Please sign in to comment.