From b49b89fde97a65a7d8eaeb0d4541b4dcf60dac07 Mon Sep 17 00:00:00 2001 From: KenTandrian Date: Sun, 8 Mar 2026 13:01:30 +0700 Subject: [PATCH] feat(lib): type safety of tags selector --- .../tags-selector/tags-selector.component.ts | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/libs/ui/src/lib/tags-selector/tags-selector.component.ts b/libs/ui/src/lib/tags-selector/tags-selector.component.ts index 7f1a8805e..42f52d4b3 100644 --- a/libs/ui/src/lib/tags-selector/tags-selector.component.ts +++ b/libs/ui/src/lib/tags-selector/tags-selector.component.ts @@ -77,7 +77,7 @@ export class GfTagsSelectorComponent this.tagInputControl.valueChanges .pipe(takeUntil(this.unsubscribeSubject)) .subscribe((value) => { - this.filteredOptions.next(this.filterTags(value)); + this.filteredOptions.next(this.filterTags(value ?? '')); }); addIcons({ addCircleOutline, closeOutline }); @@ -100,21 +100,24 @@ export class GfTagsSelectorComponent if (!tag && this.hasPermissionToCreateTag) { tag = { - id: undefined, + id: '', name: event.option.value as string, userId: null }; } - this.tagsSelected.update((tags) => { - return [...(tags ?? []), tag]; - }); + if (tag) { + this.tagsSelected.update((tags) => { + return [...(tags ?? []), tag]; + }); + + const newTags = this.tagsSelected(); + this.onChange(newTags); + this.onTouched(); + } - const newTags = this.tagsSelected(); - this.onChange(newTags); - this.onTouched(); this.tagInput.nativeElement.value = ''; - this.tagInputControl.setValue(undefined); + this.tagInputControl.setValue(null); } public onRemoveTag(tag: Tag) {