I have build a sidebar with 3 level dropdown with using Material UI "List" where I am facing issue with 3rd level dropdown all child open together when I click on any of 2nd level dropdown. I am sharing the 2nd and 3rd level code samples where I want to manage the dropdown onClick event work individually on 2nd dropdown list.
I want solution for Individual onClick on second level dropdown. where the third level open to related onClick event.
{
id: 'finance-management',
icon: <img src="/images/finance-mgt.svg" />,
name: 'Finance Management',
url: 'finance',
dropDown: [
{
id: "profit",
sublist: "Profit & Loss",
superSubList: [
{ superlist: "Payments"},
{ superlist: "Receivables"},
{ superlist: "Cashflow"},
{ superlist: "Profit & Loss Statement"},
]
},
{
id: "suppliers",
sublist: "Suppliers",
superSubList: [
{ superlist: "Overview"},
{ superlist: "Create New"}
]
}
]
},
----------------------------------------------------
const [sublistcl, setSubListcl] = useState();
const handleSubClick = () => {
setSubListcl(!sublistcl)
};
----------------------------------------------------
{menuItem?.dropDown?.map((menuSubItem) => (
<div className="sub-drop-down">
<Collapse in={open} >
<List component="div" disablePadding>
<ListItemButton sx={{ pl: 4 }}
// onClick={isExpandable && handleSubClick}
onClick={handleSubClick}
key={menuSubItem.id}
>
<ListItemText primary={menuSubItem.sublist} />
{sublistcl ? <ExpandLess /> : <ExpandMore />}
{/* {sublistcl && !sublistcl && <ExpandMore />}
{sublistcl && sublistcl && <ExpandLess />} */}
</ListItemButton>
{/* Super Sub List Item */}
{menuSubItem?.superSubList?.map((itemThird) =>(
<div className="list-item-subchild">
<Collapse in={sublistcl} >
<List component="div" disablePadding>
<ListItemButton sx={{ pl: 5 }}>
<ListItemText primary={itemThird.superlist} />
</ListItemButton>
</List>
</Collapse>
</div>
))}
</List>
</Collapse>
</div>
))}
-----------------------------------------------