I have styled a select field with a custom dropdown icon using this css on the select:
appearance: none; /* remove default arrow */
And then using an absolutely positioned icon.
Now I want that icon when clicked to trigger the click event on the select field. I have tried using ViewChild to get the select element ref and trigger a click on it's nativeElement property but nothing happens.
@ViewChild('customInput') input: ElementRef;
click() {
const ele = this.input.nativeElement as HTMLElement;
ele.click();
this.cd.detectChanges();
}
I have also tried template references:
<select #customInput>
<div class="arrow" (click)="customInput.click()"></div>
EDIT:
it is also worth noting that both approaches using .focus()
instead does focus the element, but does not cause the dropdown list to appear.