Skip to content

Commit

Permalink
enhancement: Active selected link in sidebar state
Browse files Browse the repository at this point in the history
Update sidebar.tsx
  • Loading branch information
ivyjeong13 committed Dec 2, 2024
1 parent a419617 commit 6a92fd7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 9 additions & 2 deletions ui/admin/app/components/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link } from "@remix-run/react";
import { Link, useLocation } from "@remix-run/react";
import {
BotIcon,
BrainIcon,
Expand Down Expand Up @@ -81,6 +81,7 @@ const items = [

export function AppSidebar() {
const { state } = useSidebar();
const location = useLocation();
return (
<Sidebar collapsible="icon">
<SidebarRail />
Expand Down Expand Up @@ -108,12 +109,18 @@ export function AppSidebar() {
<SidebarMenuButton
asChild
className="w-full"
isActive={location.pathname.startsWith(
item.url
)}
variant="spill"
>
<Link
to={item.url}
className="w-full flex items-center"
>
<item.icon className="mr-2" />
<item.icon
className={`mr-2 ${location.pathname.startsWith(item.url) ? "text-primary" : ""}`}
/>
<span>{item.title}</span>
</Link>
</SidebarMenuButton>
Expand Down
3 changes: 2 additions & 1 deletion ui/admin/app/components/ui/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ const SidebarContent = React.forwardRef<
ref={ref}
data-sidebar="content"
className={cn(
"flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
"flex min-h-0 flex-1 flex-col gap-2 overflow-hidden group-data-[collapsible=icon]:overflow-hidden",
className
)}
{...props}
Expand Down Expand Up @@ -534,6 +534,7 @@ const sidebarMenuButtonVariants = cva(
"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
outline:
"bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]",
spill: "w-full group-data-[collapsible=icon]:data-[active=true]:!bg-background group-data-[collapsible=icon]:data-[active=true]:!w-[calc(100%+20px)] hover:bg-background hover:w-[calc(100%+20px)] data-[active=true]:bg-background data-[active=true]:w-[calc(100%+20px)] pr-[10px]",
},
size: {
default: "h-8 text-sm",
Expand Down

0 comments on commit 6a92fd7

Please sign in to comment.