import cn from 'clsx'; import s from './Sidebar.module.css'; import { useEffect, useRef } from 'react'; import { disableBodyScroll, clearAllBodyScrollLocks } from 'body-scroll-lock'; interface SidebarProps { children: any; onClose: () => void; } const Sidebar: React.FC = ({ children, onClose }) => { const sidebarRef = useRef() as React.MutableRefObject; const contentRef = useRef() as React.MutableRefObject; const onKeyDownSidebar = (event: React.KeyboardEvent) => { if (event.code === 'Escape') { onClose(); } }; useEffect(() => { if (sidebarRef.current) { sidebarRef.current.focus(); } const contentElement = contentRef.current; if (contentElement) { disableBodyScroll(contentElement, { reserveScrollBarGap: true }); } return () => { clearAllBodyScrollLocks(); }; }, []); return (
{children}
); }; export default Sidebar;