How to toggle the dropdown? #2092
-
When clicking a dropdown, it opens but I want to close it when clicked again. I was trying to use v-show but it has an issue. My dropdown currently closes when clicked outside or when an item inside the dropdown clicked (I've used document.activeElement.blur() ). So, to sum up, my question is how do I close the dropdown not only by clicking outside, but also clicking the dropdown again? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
If you're using If you're using the Let me know if you have any questions. |
Beta Was this translation helpful? Give feedback.
-
How do I use this dropdown in solidjs and have it close when I click outside the menu, select a menu item, and re-click on the menu button? I am using the 'Method1' with details tag, and all is working except clicking ouside the menu. The components seem quite good, however I am struggling to obtain this basic functionality from the dropdown component. ( it could be helpful to update the docs to show an example on how to accomplish this ) Update: I have attached an 'onClick' event handler to window object as a work-around but not sure if this is efficient ( always called on every click, even if the dropdown menu is not open ) or could cause issues in some browsers like safari:
Many thanks |
Beta Was this translation helpful? Give feedback.
If you're using
<details>
tag it opens with click and closes with second click. You can add a JS script to close it when clicked outside or when an item is clicked. Adding or removing theopen
attribute from<details>
tag opens or closes the dropdown.If you're using the
<label>
tag, it works with CSS focus. It opens when it is focused and it closes when it loses focus so if you want it to close on the second click, you can use JS toblur
it (document.activeElement.blur()
)Let me know if you have any questions.