Skip to content

UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.

fix: mobile sidebar menu active state (#493)

Arghya Das891395616990
diff --git a/components/mobile-nav.tsx b/components/mobile-nav.tsx
index c73301f9..f3625abf 100644
--- a/components/mobile-nav.tsx
+++ b/components/mobile-nav.tsx
@@ -1,13 +1,11 @@
"use client";
-import * as React from "react";
import Link, { LinkProps } from "next/link";
-import { useRouter } from "next/navigation";
+import { usePathname, useRouter } from "next/navigation";
import posthog from "posthog-js";
+import * as React from "react";
-import { docsConfig } from "@/config/docs";
-import { siteConfig } from "@/config/site";
-import { cn } from "@/lib/utils";
+import { Icons } from "@/components/icons";
import { Button } from "@/components/ui/button";
import { ScrollArea } from "@/components/ui/scroll-area";
import {
@@ -16,7 +14,9 @@ import {
SheetContent,
SheetTrigger,
} from "@/components/ui/sheet";
-import { Icons } from "@/components/icons";
+import { docsConfig } from "@/config/docs";
+import { siteConfig } from "@/config/site";
+import { cn } from "@/lib/utils";
export function MobileNav() {
return (
@@ -58,13 +58,13 @@ export function MobileNav() {
<span className="sr-only">Toggle Menu</span>
</Button>
</SheetTrigger>
- <SheetContent side="left" className="pr-0">
+ <SheetContent side="left">
<MobileLink href="/" className="flex items-center">
<Icons.logo className="mr-2 size-4" />
<span className="font-bold">{siteConfig.name}</span>
</MobileLink>
- <ScrollArea className="my-4 h-[calc(100vh-8rem)] pb-10 pl-6">
- <div className="flex flex-col space-y-3">
+ <ScrollArea className="my-4 h-[calc(100vh-6rem)]">
+ <div className="flex flex-col space-y-1.5">
{docsConfig.mainNav?.map(
(item) =>
item.href && (
@@ -74,9 +74,9 @@ export function MobileNav() {
),
)}
</div>
- <div className="flex flex-col space-y-2">
+ <div className="flex flex-col gap-y-2">
{docsConfig.sidebarNav.map((item, index) => (
- <div key={index} className="flex flex-col space-y-3 pt-6">
+ <div key={index} className="flex flex-col gap-y-1.5 pt-6">
<h4 className="font-medium">{item.title}</h4>
{item.items?.map((item) =>
!item.disabled && item.href ? (
@@ -136,6 +136,8 @@ function MobileLink({
...props
}: MobileLinkProps) {
const router = useRouter();
+ const pathname = usePathname();
+ const isActive = pathname === href;
return (
<SheetClose asChild>
<Link
@@ -144,7 +146,13 @@ function MobileLink({
router.push(href.toString());
onOpenChange?.(false);
}}
- className={cn(className)}
+ className={cn(
+ className,
+ "p-1 pl-2.5 text-[15px]",
+ isActive
+ ? "rounded-r-md border-l-2 border-primary/70 bg-secondary font-medium text-primary"
+ : "",
+ )}
{...props}
>
{children}