[ACS-8180] Error message displayed on attempt to remove a tag (#9827)

This commit is contained in:
jacekpluta 2024-06-19 14:55:07 +02:00 committed by GitHub
parent d9c014a1f0
commit a471861356
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 3 deletions

View File

@ -7,7 +7,6 @@
autocomplete="off" autocomplete="off"
[formControl]="tagNameControl" [formControl]="tagNameControl"
(keyup.enter)="addTag()" (keyup.enter)="addTag()"
adf-auto-focus
placeholder="{{ 'TAG.TAGS_CREATOR.TAG_SEARCH_PLACEHOLDER' | translate }}" placeholder="{{ 'TAG.TAGS_CREATOR.TAG_SEARCH_PLACEHOLDER' | translate }}"
/> />
<mat-error *ngIf="tagNameControl.invalid && tagNameControl.touched">{{ tagNameErrorMessageKey | translate }} </mat-error> <mat-error *ngIf="tagNameControl.invalid && tagNameControl.touched">{{ tagNameErrorMessageKey | translate }} </mat-error>

View File

@ -289,13 +289,21 @@ describe('TagsCreatorComponent', () => {
}); });
describe('Tag name field', () => { describe('Tag name field', () => {
it('should input be autofocused', fakeAsync(() => { it('should input be autofocused when there are no tags present', fakeAsync(() => {
component.tagNameControlVisible = true; component.tagNameControlVisible = true;
fixture.detectChanges(); fixture.detectChanges();
tick(100); tick(100);
expect(getNameInput()).toBe(document.activeElement as HTMLInputElement); expect(getNameInput()).toBe(document.activeElement as HTMLInputElement);
})); }));
it('should input not be autofocused when there are tags present', fakeAsync(() => {
component.tags = ['Tag 1'];
component.tagNameControlVisible = true;
fixture.detectChanges();
tick(100);
expect(getNameInput()).not.toBe(document.activeElement as HTMLInputElement);
}));
it('should input be autofocused after showing input second time', fakeAsync(() => { it('should input be autofocused after showing input second time', fakeAsync(() => {
component.tagNameControlVisible = true; component.tagNameControlVisible = true;
fixture.detectChanges(); fixture.detectChanges();

View File

@ -94,6 +94,9 @@ export class TagsCreatorComponent implements OnInit, OnDestroy {
this._existingTagsPanelVisible = true; this._existingTagsPanelVisible = true;
setTimeout(() => { setTimeout(() => {
this.tagNameInputElement?.nativeElement?.scrollIntoView(); this.tagNameInputElement?.nativeElement?.scrollIntoView();
if (!this.tags.length) {
this.tagNameInputElement?.nativeElement?.focus();
}
}); });
} else { } else {
this._existingTagsPanelVisible = false; this._existingTagsPanelVisible = false;
@ -247,7 +250,7 @@ export class TagsCreatorComponent implements OnInit, OnDestroy {
*/ */
removeTag(tag: string): void { removeTag(tag: string): void {
this.removeTagFromArray(this.tags, tag); this.removeTagFromArray(this.tags, tag);
this.tagNameControl.updateValueAndValidity(); this.tagNameControl.updateValueAndValidity({ emitEvent: false });
this.updateExistingTagsListOnRemoveFromTagsToConfirm(tag); this.updateExistingTagsListOnRemoveFromTagsToConfirm(tag);
this.exactTagSet$.next(); this.exactTagSet$.next();
this.checkScrollbarVisibility(); this.checkScrollbarVisibility();