I recently worked on a SharePoint project where I had to create a global navigation sourced from a SharePoint list. The implementation was successful, and I created a mock-up that can be viewed here.
While w3schools provided a static version, I utilized DOM manipulation to make it dynamic using an array of objects to simulate a SharePoint list.
One particular challenge I encountered was with creating a mega-menu for the "Directorate" menu item. I merged the CSS of the Navigation with the CSS of the mega-menu, causing issues. The problem seemed to arise when adding classes to elements in the loop through the menu items from the array. Specifically, giving the mega-menu item different class names 'Mdropdown' and 'Mdropbtn' caused conflicts.
CreateNavigation(navData) {
// Existing code...
}
function buildSubNavBar(subNavID, isDirectorate) {
// Existing code...
}
I have shared a CodePen link for better clarity. Changing line 115 to `ddDiv.classList.add("Mdropdown")` and line 118 to `btn.classList.add("Mdropbtn)` helped resolve the issue with the mega-menu but caused problems with other menu items.
In addition to this challenge, I added categories and sub-categories to further enhance the mega-menu functionality. Building the mega-menu involved complex interactions between various category elements within the menu.
If you have any suggestions or solutions to address the conflicting class names and improve the overall functionality of the mega-menu, please share them. Your assistance is greatly appreciated!