From 6d7907e844a909993d185759d660632f55aeaa35 Mon Sep 17 00:00:00 2001 From: Brandon Cohen Date: Tue, 15 Dec 2020 20:58:41 -0500 Subject: [PATCH] fix(frontend): close sidebar when clicking outside (#333) --- src/components/Layout/Sidebar/index.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/Layout/Sidebar/index.tsx b/src/components/Layout/Sidebar/index.tsx index b5de5f2e8..b6e44f37d 100644 --- a/src/components/Layout/Sidebar/index.tsx +++ b/src/components/Layout/Sidebar/index.tsx @@ -1,9 +1,10 @@ -import React, { ReactNode } from 'react'; +import React, { ReactNode, useRef } from 'react'; import Transition from '../../Transition'; import Link from 'next/link'; import { useRouter } from 'next/router'; import { defineMessages, FormattedMessage } from 'react-intl'; import { useUser, Permission } from '../../../hooks/useUser'; +import useClickOutside from '../../../hooks/useClickOutside'; const messages = defineMessages({ dashboard: 'Discover', @@ -116,8 +117,10 @@ const SidebarLinks: SidebarLinkProps[] = [ ]; const Sidebar: React.FC = ({ open, setClosed }) => { + const navRef = useRef(null); const router = useRouter(); const { hasPermission } = useUser(); + useClickOutside(navRef, () => setClosed()); return ( <>
@@ -166,7 +169,10 @@ const Sidebar: React.FC = ({ open, setClosed }) => {
-
+