I have come across a dilemma regarding a dropdown menu that needs to cater to both Desktop/PC users (with mouse) and Mobile devices (with touch).
After considering my options, here are the proposed solutions:
OPTION 1
One approach is to implement it using :hover
and address potential issues such as removing the :hover
state on mobile devices after a user clicks on a dropdown item.
OPTION 2
Alternatively, another solution could involve utilizing React's
const [open,setOpen] = useState(boolean)
to manage the dropdown. This method would require listening for click
events (more common on mobile) as well as mouseEnter
and mouseLeave
events (primarily occurring on PC/Desktop).
Is there a recommended best practice for handling this scenario? What are the advantages and disadvantages of each option?