fix(web): smooth settings sidebar transitions (#9811)

This commit is contained in:
Julius Marminge authored and GitHub committed 2026-09-04 17:06:27 -07:00
1 parent 4f1092cec2
commit 2e61301b13
1 file changed
+39 -16
@@ -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>
);