Skip to content

Commit

Permalink
Fix: sidebar toggle functionality from button click (#1403) (#1410)
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberSpyderX authored Oct 4, 2024
1 parent c2ea658 commit 7fe2cbd
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function Sidebar({
number[]
>([]);
const sidebarRef = useRef<HTMLDivElement | null>(null);
const buttonRef = useRef<HTMLButtonElement | null>(null);
const closeSidebar = () => setSidebarOpen(false);

const findPathToContent = useCallback(
Expand Down Expand Up @@ -75,7 +76,8 @@ export function Sidebar({
const handleClickOutside = (event: MouseEvent) => {
if (
sidebarRef.current &&
!sidebarRef.current.contains(event.target as Node)
!sidebarRef.current.contains(event.target as Node) &&
!buttonRef.current?.contains(event.target as Node)
) {
closeSidebar();
}
Expand Down Expand Up @@ -185,7 +187,11 @@ export function Sidebar({

return (
<>
<Button onClick={() => setSidebarOpen((s) => !s)} className="w-fit gap-2">
<Button
ref={buttonRef}
onClick={() => setSidebarOpen((s) => !s)}
className="w-fit gap-2"
>
{sidebarOpen ? <X className="size-5" /> : <Menu className="size-5" />}
<span>{sidebarOpen ? 'Hide Contents' : 'Show Contents'}</span>
</Button>
Expand Down

0 comments on commit 7fe2cbd

Please sign in to comment.