ReactJS: Dynamically update dropdown menu icon on hover
P粉877114798
P粉877114798 2024-03-29 17:58:41
0
1
443

First, I used the "antd" React framework and tailwindCSS just to practice ReactJS. Well, this is my first time using this framework. So I decided to first try using a dropdown popup on hover.

Actually, it’s not quite clear how to reach this stage. Of course I know that using CSS I can use "hover:" attr, but any ideas on using logic in ReactJS? Also, I tried reading the prop "API section for dropdown menus" without success. Even if I try to use onMouseEnter() as a prop in <Dropdown> I still can't get this.

I've shared this code and box to show the current status.

This is a codesandbox link

I want to change the icon of the dropdown menu on hover using <UpOutlined /> and <DownOutlined />, this is what I got from "@antd" in ReactJS /icons" to import content, I use tailwind CSS.

As expected, I want something like this: Hover menu demo for dummy website

Any help would be greatly appreciated, I've been trying to achieve this since yesterday :(

P粉877114798
P粉877114798

reply all(1)
P粉894008490

You can use the onOpenChange function on Dropdown to get the open status, see Dropdown props. You can use this to set some status of your own. Finally use this state to display different icons.

const [isOpen, setIsOpen] = useState(false);

return (
  
    
      Hover me, Click menu item
      {isOpen ?  : }
    
  
);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template