P
P
ploskost2021-03-24 22:38:00
css
ploskost, 2021-03-24 22:38:00

How to disable function triggering when clicking outside select'a?

Hello, I need help. I seem to have climbed into some jungle, but I want to figure it out.

https://jsitor.com/KiJLwEGPtz

When the select is clicked, the function to rotate the arrow is executed, but if you click outside the select, the arrow remains in the rotated state, and the select closes accordingly.

Which of the options is easier to implement, and is it possible?
1) Returning the arrow to its original position if clicked outside the select;
2) Prevent select from closing if there was a click outside of it.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
twobomb, 2018-03-14
@vovandon

Like this

A
Anton, 2018-03-14
@karminski

Hint:
* border-radius
* https://css-tricks.com/snippets/css/css-triangle/ + content: ""
Implement it yourself

S
skuvaWeb, 2021-03-25
@ploskost

Solution
1) It's possible. Google how to catch a click outside the element, there is nothing complicated
2) Since this is a native select, I'm not sure if this is even possible
. In your case, you just need to synchronize the state of the arrow and the select. You can subscribe to blur (closing) & focus (opening) events. And set the desired state of the arrow

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question