diff --git a/client/src/common/types.ts b/client/src/common/types.ts index ec9876c9e4..1c2ff06c9e 100644 --- a/client/src/common/types.ts +++ b/client/src/common/types.ts @@ -571,8 +571,6 @@ export interface ModelItemProps { export type ContextType = { navVisible: boolean; setNavVisible: React.Dispatch>; - openSidebarRef?: React.RefObject; - closeSidebarRef?: React.RefObject; }; export interface SwitcherProps { diff --git a/client/src/components/Chat/Header.tsx b/client/src/components/Chat/Header.tsx index 966e4ad205..425cadeba3 100644 --- a/client/src/components/Chat/Header.tsx +++ b/client/src/components/Chat/Header.tsx @@ -18,8 +18,7 @@ const defaultInterface = getConfigDefaults().interface; export default function Header() { const { data: startupConfig } = useGetStartupConfig(); - const { navVisible, setNavVisible, openSidebarRef, closeSidebarRef } = - useOutletContext(); + const { navVisible, setNavVisible } = useOutletContext(); const interfaceConfig = useMemo( () => startupConfig?.interface ?? defaultInterface, @@ -52,12 +51,7 @@ export default function Header() { transition={{ duration: 0.2 }} key="header-buttons" > - + )} diff --git a/client/src/components/Chat/Menus/OpenSidebar.tsx b/client/src/components/Chat/Menus/OpenSidebar.tsx index 5be467bb0c..e5a76ff4b4 100644 --- a/client/src/components/Chat/Menus/OpenSidebar.tsx +++ b/client/src/components/Chat/Menus/OpenSidebar.tsx @@ -1,16 +1,19 @@ -import { forwardRef } from 'react'; import { TooltipAnchor, Button, Sidebar } from '@librechat/client'; import { useLocalize } from '~/hooks'; import { cn } from '~/utils'; -const OpenSidebar = forwardRef< - HTMLButtonElement, - { - setNavVisible: React.Dispatch>; - className?: string; - closeSidebarRef?: React.RefObject; - } ->(({ setNavVisible, className, closeSidebarRef }, ref) => { +/** Element ID for the close sidebar button - used for focus management */ +export const CLOSE_SIDEBAR_ID = 'close-sidebar-button'; +/** Element ID for the open sidebar button - used for focus management */ +export const OPEN_SIDEBAR_ID = 'open-sidebar-button'; + +export default function OpenSidebar({ + setNavVisible, + className, +}: { + setNavVisible: React.Dispatch>; + className?: string; +}) { const localize = useLocalize(); const handleClick = () => { @@ -18,9 +21,10 @@ const OpenSidebar = forwardRef< localStorage.setItem('navVisible', JSON.stringify(!prev)); return !prev; }); - requestAnimationFrame(() => { - closeSidebarRef?.current?.focus(); - }); + // Delay focus until after the sidebar animation completes (200ms) + setTimeout(() => { + document.getElementById(CLOSE_SIDEBAR_ID)?.focus(); + }, 250); }; return ( @@ -28,7 +32,7 @@ const OpenSidebar = forwardRef< description={localize('com_nav_open_sidebar')} render={