Adding focus to the input after the reset button is clicked

This commit is contained in:
andreaNeki
2024-09-27 14:01:44 -03:00
committed by Tim Donohue
parent b601405e56
commit 14680b013e
2 changed files with 8 additions and 2 deletions

View File

@@ -2,7 +2,7 @@
<div class="treeview-header row mb-1">
<div class="col-12">
<div class="input-group">
<input type="text" class="form-control" [(ngModel)]="searchText" (keyup.enter)="search()"
<input #searchInput type="text" class="form-control" [(ngModel)]="searchText" (keyup.enter)="search()"
[attr.aria-label]="'vocabulary-treeview.search.form.search-placeholder' | translate"
[placeholder]="'vocabulary-treeview.search.form.search-placeholder' | translate">
<div class="input-group-append" id="button-addon4">

View File

@@ -1,5 +1,5 @@
import { FlatTreeControl } from '@angular/cdk/tree';
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output, OnChanges, SimpleChanges } from '@angular/core';
import { Component, ElementRef, EventEmitter, Input, OnDestroy, OnInit, Output, OnChanges, SimpleChanges, ViewChild } from '@angular/core';
import { Observable, Subscription } from 'rxjs';
import { Store } from '@ngrx/store';
@@ -29,6 +29,11 @@ import { AlertType } from '../../alert/alert-type';
})
export class VocabularyTreeviewComponent implements OnDestroy, OnInit, OnChanges {
/**
* Implemented to manage focus on input
*/
@ViewChild('searchInput') searchInput: ElementRef;
/**
* The {@link VocabularyOptions} object
*/
@@ -294,6 +299,7 @@ export class VocabularyTreeviewComponent implements OnDestroy, OnInit, OnChanges
this.storedNodeMap = new Map<string, TreeviewFlatNode>();
this.vocabularyTreeviewService.restoreNodes();
}
this.searchInput.nativeElement.focus();
}
add() {