I'm working on a select dropdown that resembles a material UI dropdown. I've added icons for an arrow up and arrow down to indicate the state of the dropdown. The aim is to show the arrow up when the dropdown is open and switch to the arrow down icon when it's closed. Currently, clicking on the dropdown displays the arrow up, but if you click again and the dropdown isn't visible, I want the arrow down functionality. How can this be achieved?
<select className="Select">
<option value="">Select</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4">Option 4</option>
</select>
CSS Code
.Select {
font-size: 1.5rem;
width: 10rem;
border-left: none;
border-right: none;
border-top: none;
border-bottom: 2px solid blue;
padding-bottom: 2px;
color: var(--deepGray);
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chevron-down" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z"/></svg>')
no-repeat right;
-webkit-appearance: none;
}
.Select:hover {
color: blue;
background: white;
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chevron-down" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z"/></svg>')
no-repeat right;
}
.Select:focus {
outline: none;
box-shadow: none;
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chevron-up" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M7.646 4.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1-.708.708L8 5.707l-5.646 5.647a.5.5 0 0 1-.708-.708l6-6z"/></svg>')
no-repeat right;
background-position: right;
}
In cases where the dropdown is not present, the arrow down should be displayed https://i.sstatic.net/OXE8r.png