diff --git a/lib/content-services/src/lib/tag/tags-creator/tags-creator.component.html b/lib/content-services/src/lib/tag/tags-creator/tags-creator.component.html index 9e5ff19844..d98a9e4cc5 100644 --- a/lib/content-services/src/lib/tag/tags-creator/tags-creator.component.html +++ b/lib/content-services/src/lib/tag/tags-creator/tags-creator.component.html @@ -7,7 +7,6 @@ autocomplete="off" [formControl]="tagNameControl" (keyup.enter)="addTag()" - adf-auto-focus placeholder="{{ 'TAG.TAGS_CREATOR.TAG_SEARCH_PLACEHOLDER' | translate }}" /> {{ tagNameErrorMessageKey | translate }} diff --git a/lib/content-services/src/lib/tag/tags-creator/tags-creator.component.spec.ts b/lib/content-services/src/lib/tag/tags-creator/tags-creator.component.spec.ts index 841a22af7c..78e70cc791 100644 --- a/lib/content-services/src/lib/tag/tags-creator/tags-creator.component.spec.ts +++ b/lib/content-services/src/lib/tag/tags-creator/tags-creator.component.spec.ts @@ -289,13 +289,21 @@ describe('TagsCreatorComponent', () => { }); 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; fixture.detectChanges(); tick(100); 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(() => { component.tagNameControlVisible = true; fixture.detectChanges(); diff --git a/lib/content-services/src/lib/tag/tags-creator/tags-creator.component.ts b/lib/content-services/src/lib/tag/tags-creator/tags-creator.component.ts index cda27b020f..ae6a36bfa0 100644 --- a/lib/content-services/src/lib/tag/tags-creator/tags-creator.component.ts +++ b/lib/content-services/src/lib/tag/tags-creator/tags-creator.component.ts @@ -94,6 +94,9 @@ export class TagsCreatorComponent implements OnInit, OnDestroy { this._existingTagsPanelVisible = true; setTimeout(() => { this.tagNameInputElement?.nativeElement?.scrollIntoView(); + if (!this.tags.length) { + this.tagNameInputElement?.nativeElement?.focus(); + } }); } else { this._existingTagsPanelVisible = false; @@ -247,7 +250,7 @@ export class TagsCreatorComponent implements OnInit, OnDestroy { */ removeTag(tag: string): void { this.removeTagFromArray(this.tags, tag); - this.tagNameControl.updateValueAndValidity(); + this.tagNameControl.updateValueAndValidity({ emitEvent: false }); this.updateExistingTagsListOnRemoveFromTagsToConfirm(tag); this.exactTagSet$.next(); this.checkScrollbarVisibility();