Currently, in my react project, I am implementing dropdown menus using the reactstrap css framework.
Example.Js
<Dropdown
className="d-inline-block"
onMouseOver={this.onMouseEnter}
onMouseLeave={this.onMouseLeave}
isOpen={this.state.dropdownOpen}
toggle={this.toggle}
>
<DropdownToggle caret>Dropdown1</DropdownToggle>
<DropdownMenu>
<DropdownItem header>Submenu 1</DropdownItem>
<DropdownItem>Submenu 1.1</DropdownItem>
</DropdownMenu>
<DropdownToggle caret>Dropdown2</DropdownToggle>
<DropdownMenu>
<DropdownItem header>Submenu 2</DropdownItem>
<DropdownItem>Submenu 2.1</DropdownItem>
<DropdownItem>Submenu 2.2</DropdownItem>
</DropdownMenu>
<br /><br />
<DropdownToggle caret>Dropdown3</DropdownToggle>
<DropdownMenu>
<DropdownItem header>Submenu 3</DropdownItem>
<DropdownItem>Submenu 3.1</DropdownItem>
<DropdownItem>Submenu 3.2</DropdownItem>
<DropdownItem>Submenu 3.3</DropdownItem>
</DropdownMenu>
</Dropdown>
In the above code, I have used the setState
method to manage the state of dropdownOpen
based on the onMouseOver
and onMouseLeave
events.
However, the main problem I am facing is that when I hover over a single dropdown menu, all dropdowns open at the same time.
To see a Working Demo, click here.
I am looking for assistance in modifying the hover dropdown functionality to only display the menu of the dropdown being hovered over and not all menus simultaneously.
Note: The dropdown menus in my actual application will be dynamically generated, and hence, I cannot use hardcoded states like dropDown1
, dropDown2
, dropDown3
, etc.
Since the number of dropdowns may vary, I need a solution that can handle the dynamic nature of the menus.