How to blur input
by pressing native keyboard return button
on mobile ?
For example :
<input type="text" #search>
this.search.blur() //-- unfocus and hide keyboard
If you want to fire blur event with key enter event, then simply pass $event in function and $event. target. blur(); in the function.
blur() method removes keyboard focus from the current element.
In this article, we are going to see what is blur event in Angular 10 and how to use it. The blur event is triggered when an element loses its focus. Syntax: <input (blur)='functionName()'/>
(keyup): (keyup) is an Angular event binding to respond to any DOM event. It is a synchronous event that is triggered as the user is interacting with the text-based input controls. When a user presses and releases a key, the (keyup) event occurs.
html file
<input type="text" #search (keyup.enter)="doSomething()">
.ts file
import { Component, ViewChild, ElementRef} from '@angular/core';
@ViewChild('search') search: ElementRef;
doSomething(): void {
this.search.nativeElement.blur()
}
working stackblitz
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With