TypeScript
fix(web): smooth settings sidebar transitions (#9811)
Julius Marminge2e61301b1325
diff --git a/apps/web/src/components/settings/SettingsSidebarNav.tsx b/apps/web/src/components/settings/SettingsSidebarNav.tsxindex 2716569c571..4f851c9b804 100644--- a/apps/web/src/components/settings/SettingsSidebarNav.tsx+++ b/apps/web/src/components/settings/SettingsSidebarNav.tsx@@ -8,6 +8,7 @@ import {useState,type ComponentType,type KeyboardEvent,+ type ReactNode,} from "react";import {ArchiveIcon,@@ -24,6 +25,7 @@ import {import { useLocation, useNavigate } from "@tanstack/react-router";import { Button } from "../ui/button";+import { Collapsible, CollapsiblePanel } from "../ui/collapsible";import { Input } from "../ui/input";import { Kbd } from "../ui/kbd";import {@@ -114,6 +116,22 @@ function SettingsSectionIcon({ to }: { to: SettingsPath }) {return <Icon className="mt-0.5 size-3.5 shrink-0 text-sidebar-muted-foreground/60" />;}+function SettingsSubmenuCollapse({+ open,+ children,+}: {+ readonly open: boolean;+ readonly children: ReactNode;+}) {+ return (+ <Collapsible open={open}>+ <CollapsiblePanel className="duration-150 ease-out motion-reduce:transition-none">+ {children}+ </CollapsiblePanel>+ </Collapsible>+ );+}+export function SettingsSidebarNav({ pathname }: { pathname: string }) {const navigate = useNavigate();const currentHash = useLocation({ select: (location) => location.hash });@@ -125,6 +143,9 @@ export function SettingsSidebarNav({ pathname }: { pathname: string }) {const results = useMemo(() => searchSettings(query, searchableItems), [query, searchableItems]);const isSearching = query.trim().length > 0;const hasResults = results.length > 0;+ const activeSettingsPath = SETTINGS_NAV_ITEMS.find(+ (item) => pathname === item.to || pathname.startsWith(`${item.to}/`),+ )?.to;useEffect(() => {setActiveResultIndex((index) => Math.min(index, Math.max(results.length - 1, 0)));@@ -347,8 +368,8 @@ export function SettingsSidebarNav({ pathname }: { pathname: string }) {<SidebarMenu className="ps-px">{SETTINGS_NAV_ITEMS.map((item) => {const Icon = item.icon;- const isActive = pathname === item.to || pathname.startsWith(`${item.to}/`);const pageSections = SETTINGS_PAGE_SECTIONS[item.to];+ const isActive = activeSettingsPath === item.to;return (<SidebarMenuItem key={item.to}><SidebarMenuButton@@ -358,21 +379,23 @@ export function SettingsSidebarNav({ pathname }: { pathname: string }) {<Icon /><span className="truncate">{item.label}</span></SidebarMenuButton>- {isActive && pageSections ? (- <SidebarMenuSub className="border-l-0">- {pageSections.map((section) => (- <SidebarMenuSubItem key={section.targetId}>- <SidebarMenuSubButton- render={<button type="button" />}- size="sm"- className="w-full text-sidebar-muted-foreground/65"- onClick={() => handlePageSectionClick(item.to, section.targetId)}- >- <span className="ms-0.5">{section.label}</span>- </SidebarMenuSubButton>- </SidebarMenuSubItem>- ))}- </SidebarMenuSub>+ {pageSections ? (+ <SettingsSubmenuCollapse open={isActive}>+ <SidebarMenuSub className="border-l-0">+ {pageSections.map((section) => (+ <SidebarMenuSubItem key={section.targetId}>+ <SidebarMenuSubButton+ render={<button type="button" />}+ size="sm"+ className="w-full text-sidebar-muted-foreground/65"+ onClick={() => handlePageSectionClick(item.to, section.targetId)}+ >+ <span className="ms-0.5">{section.label}</span>+ </SidebarMenuSubButton>+ </SidebarMenuSubItem>+ ))}+ </SidebarMenuSub>+ </SettingsSubmenuCollapse>) : null}</SidebarMenuItem>);