The below problem is related to Blur not working - Angular 2 thread.
I have a shared component of custom select and I am trying to add a blur event to close when the component is not in focus.
// HTML
<div (blur)="closeDropDown()" tabindex="0">
<span (click)="selectClicked()" class="placeholder">
Select Item
</span>
<div class="options">
<ul>
<li *ngFor="let item of data">
<span>{{item}}</span></li>
</ul>
</div>
//TS
selectClicked() {
this.dropdownOpen = true;
}
closeDropDown() {
this.dropdownOpen = false;
}
I was able to implement the blur event by adding the tabindex mentioned in the thread(works in all browsers except IE). But blur event is not firing in IE(version > 10).
I tried to use focusout instead of blur but the selected value is not getting attached to the custom select and requires many selections to select an option.
Why does blur is not triggering on div and are there any alternatives that I can use on block level elements?