Skip to content
Advertisement

show and hide associated sub menu when particular menu is clicked

I am designing a responsive mega navigation bar using reactjs. It’s working for desktop device but on mobile view, I could not able to show or hide sub menu when its associated parent menu is clicked. This is what I am trying to do

JavaScript

I have a code on sandbox as well and here it is

https://codesandbox.io/s/weathered-resonance-9n2hr?file=/src/mega-menu/index.js:50-4734

Advertisement

Answer

You should set active only to the activeMenuName that is clicked. Also when click go back you should reset activeMenuName to the default state. Also, I check if toggle is enabled so only onClick events are enabled and vice versa.

Check my code it’s tested.

JavaScript

The sandbox Link https://codesandbox.io/s/nifty-cloud-kuryf?file=/src/mega-menu/index.js

Advertisement