From: SleeplessOne1917 Date: Tue, 13 Jun 2023 02:24:24 +0000 (+0000) Subject: Fix mobile menu collapse bug (#1222) X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%22https:/nerdica.net/%7Biframely.url%7D?a=commitdiff_plain;h=2053c4e4e11cf3ed2a646feee631a86155c9e359;p=lemmy-ui.git Fix mobile menu collapse bug (#1222) --- diff --git a/src/shared/components/app/navbar.tsx b/src/shared/components/app/navbar.tsx index 28fca15..751bf9b 100644 --- a/src/shared/components/app/navbar.tsx +++ b/src/shared/components/app/navbar.tsx @@ -46,13 +46,12 @@ interface NavbarState { } function handleCollapseClick(i: Navbar) { - if (i.collapseButtonRef.current?.ariaExpanded === "true") { - i.collapseButtonRef.current?.click(); - } + i.collapseButtonRef.current?.click(); } -function handleLogOut() { +function handleLogOut(i: Navbar) { UserService.Instance.logout(); + handleCollapseClick(i); } export class Navbar extends Component { @@ -68,12 +67,14 @@ export class Navbar extends Component { }; subscription: any; collapseButtonRef = createRef(); + mobileMenuRef = createRef(); constructor(props: any, context: any) { super(props, context); this.parseMessage = this.parseMessage.bind(this); this.subscription = wsSubscribe(this.parseMessage); + this.handleOutsideMenuClick = this.handleOutsideMenuClick.bind(this); } componentDidMount() { @@ -109,6 +110,8 @@ export class Navbar extends Component { UserService.Instance.unreadApplicationCountSub.subscribe(res => { this.setState({ unreadApplicationCount: res }); }); + + document.addEventListener("click", this.handleOutsideMenuClick); } } @@ -118,6 +121,7 @@ export class Navbar extends Component { this.unreadInboxCountSub.unsubscribe(); this.unreadReportCountSub.unsubscribe(); this.unreadApplicationCountSub.unsubscribe(); + document.removeEventListener("click", this.handleOutsideMenuClick); } // TODO class active corresponding to current page @@ -212,7 +216,11 @@ export class Navbar extends Component { > -