Skip to content

How to toggle the dropdown? #2092

Closed Answered by saadeghi
esphoenixc asked this question in Q&A
Discussion options

You must be logged in to vote

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 the open 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 to blur it (document.activeElement.blur())

Let me know if you have any questions.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@esphoenixc
Comment options

Answer selected by saadeghi
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants