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
parent 9565f9b9ee
commit e54b1ce274
2 changed files with 9 additions and 1 deletions

View File

@@ -2,7 +2,7 @@
<div class="treeview-header row mb-1"> <div class="treeview-header row mb-1">
<div class="col-12"> <div class="col-12">
<div class="input-group"> <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" [attr.aria-label]="'vocabulary-treeview.search.form.search-placeholder' | translate"
[placeholder]="'vocabulary-treeview.search.form.search-placeholder' | translate"> [placeholder]="'vocabulary-treeview.search.form.search-placeholder' | translate">
<div class="input-group-append" id="button-addon4"> <div class="input-group-append" id="button-addon4">

View File

@@ -8,6 +8,7 @@ import {
} from '@angular/common'; } from '@angular/common';
import { import {
Component, Component,
ElementRef,
EventEmitter, EventEmitter,
Input, Input,
OnChanges, OnChanges,
@@ -15,6 +16,7 @@ import {
OnInit, OnInit,
Output, Output,
SimpleChanges, SimpleChanges,
ViewChild,
} from '@angular/core'; } from '@angular/core';
import { FormsModule } from '@angular/forms'; import { FormsModule } from '@angular/forms';
import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap'; import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';
@@ -70,6 +72,11 @@ export type VocabularyTreeItemType = FormFieldMetadataValueObject | VocabularyEn
}) })
export class VocabularyTreeviewComponent implements OnDestroy, OnInit, OnChanges { export class VocabularyTreeviewComponent implements OnDestroy, OnInit, OnChanges {
/**
* Implemented to manage focus on input
*/
@ViewChild('searchInput') searchInput: ElementRef;
/** /**
* The {@link VocabularyOptions} object * The {@link VocabularyOptions} object
*/ */
@@ -332,6 +339,7 @@ export class VocabularyTreeviewComponent implements OnDestroy, OnInit, OnChanges
this.storedNodeMap = new Map<string, TreeviewFlatNode>(); this.storedNodeMap = new Map<string, TreeviewFlatNode>();
this.vocabularyTreeviewService.restoreNodes(); this.vocabularyTreeviewService.restoreNodes();
} }
this.searchInput.nativeElement.focus();
} }
add() { add() {