Skip to content

Commit

Permalink
fix submenu collapse
Browse files Browse the repository at this point in the history
  • Loading branch information
Fisico committed Mar 8, 2024
1 parent 23cfc42 commit bbbf157
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
31 changes: 18 additions & 13 deletions src/containers/MenuItem.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
import React, { useState } from 'react';


const MenuItem = ({ label, icon, onClick, isActive, children, link }) => {
const [isOpen, setIsOpen] = useState(false);

const handleClick = () => {
const handleParentClick = (e) => {
if (children) {
e.stopPropagation();
setIsOpen(!isOpen);
} else {
}
};

const handleChildClick = (e) => {
if (!children) {
e.stopPropagation();
onClick();
}
};

return (
<a href={link}>
<li className={isActive ? 'active' : ''} onClick={handleClick}>
<div className='menuEntry'>
{icon}
<p>{label}</p>
</div>
<div className='submenu'>
{isOpen && children}
</div>
</li>
<a href={link} onClick={handleChildClick}>
<li className={isActive ? 'active' : ''} onClick={handleParentClick}>
<div className='menuEntry'>
{icon}
<p>{label}</p>
</div>
<div className='submenu'>
{isOpen && children}
</div>
</li>
</a>
);
};
Expand Down
10 changes: 1 addition & 9 deletions src/containers/TheSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import "../scss/sidebar.scss";
const TheSidebar = ({ showSidebar, setShowSidebar, isMobile }) => {

const [currentElement, setCurrentElement] = useState(window.location.hash.substring(2));
const [openSubmenu, setOpenSubmenu] = useState(null);


const itemClicked = (link) => {
if (isMobile) {
Expand All @@ -34,13 +32,7 @@ const TheSidebar = ({ showSidebar, setShowSidebar, isMobile }) => {
setCurrentElement(link);
}

const toggleSubmenu = (submenu) => {
if (openSubmenu === submenu) {
setOpenSubmenu(null);
} else {
setOpenSubmenu(submenu);
}
}


const menuItems = [
{ label: 'Groups', icon: <FaUser style={{ color: "#D85BCD" }} />, link: '#' },
Expand Down

0 comments on commit bbbf157

Please sign in to comment.