diff --git a/frontend/src/app/shared/ui/autocomplete/app-autocomplete-base.directive.ts b/frontend/src/app/shared/ui/autocomplete/app-autocomplete-base.directive.ts index a6799bc45..1d4e8d5e4 100644 --- a/frontend/src/app/shared/ui/autocomplete/app-autocomplete-base.directive.ts +++ b/frontend/src/app/shared/ui/autocomplete/app-autocomplete-base.directive.ts @@ -1,6 +1,7 @@ import { booleanAttribute, computed, + contentChild, Directive, inject, input, @@ -10,23 +11,16 @@ import { viewChild, } from '@angular/core'; import { Combobox } from '@angular/aria/combobox'; -import { CdkConnectedOverlay, Overlay } from '@angular/cdk/overlay'; -import { cn } from '../cn'; -import { - connectedOverlayPanelClass, - connectedOverlayPositions, - connectedOverlayScrollStrategy, - refreshConnectedOverlayPosition, -} from '../connected-overlay'; import { APP_FIELD } from '../field/app-field.context'; import { type AppInputSize } from '../input/app-input.variants'; +import { type TagSize } from '../tag/app-tag.variants'; import { - overlayListEmptyItemClass, - overlayListOptionClass, - overlayListRootClass, - overlayListSurfaceClass, -} from '../overlay-list.styles'; + toAutocompleteOption, + type AppAutocompleteOption, + type AppAutocompleteSuggestion, +} from './app-autocomplete-option'; +import { AppAutocompleteOptionTemplateDirective } from './app-autocomplete-option-template.directive'; import { autocompleteBoxVariants } from './app-autocomplete.variants'; @Directive() @@ -35,12 +29,15 @@ export abstract class AppAutocompleteBaseDirective { readonly required = input(false, { transform: booleanAttribute }); readonly invalid = input(false, { transform: booleanAttribute }); readonly pending = input(false, { transform: booleanAttribute }); + readonly loadingMore = input(false, { transform: booleanAttribute }); + readonly hasMore = input(false, { transform: booleanAttribute }); + readonly errored = input(false, { transform: booleanAttribute }); readonly readonly = input(false, { transform: booleanAttribute }); readonly touched = model(false); readonly name = input(''); readonly allowCustom = input(true, { transform: booleanAttribute }); - readonly suggestions = input([]); + readonly suggestions = input([]); readonly size = input('md'); readonly placeholder = input(''); readonly emptyMessage = input(''); @@ -49,12 +46,13 @@ export abstract class AppAutocompleteBaseDirective { readonly ariaDescribedBy = input(''); readonly complete = output(); + readonly opened = output(); + readonly loadMore = output(); private readonly fieldContext = inject(APP_FIELD, { optional: true }); - private readonly overlayService = inject(Overlay); protected readonly combobox = viewChild(Combobox); - private readonly overlay = viewChild(CdkConnectedOverlay); private readonly input = viewChild>('input'); + protected readonly optionTemplate = contentChild(AppAutocompleteOptionTemplateDirective); protected readonly resolvedInputId = computed(() => this.inputId() || this.fieldContext?.controlId() || null); protected readonly resolvedDescribedBy = computed( @@ -62,15 +60,12 @@ export abstract class AppAutocompleteBaseDirective { ); protected readonly showInvalid = computed(() => this.invalid() && (this.fieldContext?.validationVisible() ?? true)); protected readonly isUnavailable = computed(() => this.disabled() || this.readonly()); - - protected readonly overlayPositions = connectedOverlayPositions; - protected readonly overlayScrollStrategy = connectedOverlayScrollStrategy(this.overlayService); + protected readonly normalizedSuggestions = computed(() => + this.suggestions().map(toAutocompleteOption), + ); + protected readonly selectedTagSize = computed(() => (this.size() === 'sm' ? 'sm' : 'md')); protected readonly innerInputClass = 'min-w-[6rem] flex-1 border-0 bg-transparent p-0 text-inherit outline-hidden placeholder:text-text-muted disabled:cursor-default'; - protected readonly surfaceClass = cn(overlayListSurfaceClass, connectedOverlayPanelClass, 'box-border w-full p-0'); - protected readonly listClass = cn(overlayListRootClass, 'max-h-60 overflow-y-auto overscroll-contain p-1'); - protected readonly optionClass = overlayListOptionClass; - protected readonly emptyClass = overlayListEmptyItemClass; protected readonly boxClass = computed(() => autocompleteBoxVariants({ size: this.size(), disabled: this.disabled(), invalid: this.showInvalid() }), @@ -82,8 +77,13 @@ export abstract class AppAutocompleteBaseDirective { input.focus(); } - protected onOverlayAttach(): void { - refreshConnectedOverlayPosition(this.overlay()); + protected onInputFocus(): void { + if (this.isUnavailable()) return; + this.opened.emit(); + } + + protected closePopup(): void { + this.combobox()?.close(); } focus(options?: FocusOptions): void { diff --git a/frontend/src/app/shared/ui/autocomplete/app-autocomplete-option-template.directive.ts b/frontend/src/app/shared/ui/autocomplete/app-autocomplete-option-template.directive.ts new file mode 100644 index 000000000..c72f7c7a9 --- /dev/null +++ b/frontend/src/app/shared/ui/autocomplete/app-autocomplete-option-template.directive.ts @@ -0,0 +1,15 @@ +import { Directive, TemplateRef, inject } from '@angular/core'; + +import { type AppAutocompleteOption } from './app-autocomplete-option'; + +export interface AppAutocompleteOptionContext { + $implicit: AppAutocompleteOption; +} + +@Directive({ + selector: 'ng-template[appAutocompleteOption]', + standalone: true, +}) +export class AppAutocompleteOptionTemplateDirective { + readonly template = inject>>(TemplateRef); +} diff --git a/frontend/src/app/shared/ui/autocomplete/app-autocomplete-option.ts b/frontend/src/app/shared/ui/autocomplete/app-autocomplete-option.ts new file mode 100644 index 000000000..41930b5d9 --- /dev/null +++ b/frontend/src/app/shared/ui/autocomplete/app-autocomplete-option.ts @@ -0,0 +1,11 @@ +export interface AppAutocompleteOption { + value: string; + label: string; + data?: T; +} + +export type AppAutocompleteSuggestion = string | AppAutocompleteOption; + +export function toAutocompleteOption(suggestion: AppAutocompleteSuggestion): AppAutocompleteOption { + return typeof suggestion === 'string' ? { value: suggestion, label: suggestion } : suggestion; +} diff --git a/frontend/src/app/shared/ui/autocomplete/app-autocomplete-popup.component.ts b/frontend/src/app/shared/ui/autocomplete/app-autocomplete-popup.component.ts new file mode 100644 index 000000000..58ed47a14 --- /dev/null +++ b/frontend/src/app/shared/ui/autocomplete/app-autocomplete-popup.component.ts @@ -0,0 +1,248 @@ +import { + afterRenderEffect, + ChangeDetectionStrategy, + Component, + computed, + effect, + inject, + input, + linkedSignal, + output, + viewChild, + viewChildren, + type ElementRef, + type TemplateRef, +} from '@angular/core'; +import { NgTemplateOutlet } from '@angular/common'; +import { ComboboxPopupContainer } from '@angular/aria/combobox'; +import { Listbox, Option } from '@angular/aria/listbox'; +import { + CdkConnectedOverlay, + type ConnectedPosition, + Overlay, + OverlayModule, + type ScrollStrategy, +} from '@angular/cdk/overlay'; +import { TranslocoPipe } from '@jsverse/transloco'; +import { LucideLoaderCircle } from '@lucide/angular'; + +import { cn } from '../cn'; +import { + connectedOverlayPanelClass, + connectedOverlayPositions, + connectedOverlayScrollStrategy, + refreshConnectedOverlayPosition, +} from '../connected-overlay'; +import { + overlayListEmptyItemClass, + overlayListOptionClass, + overlayListRootClass, + overlayListSurfaceClass, +} from '../overlay-list.styles'; +import { type AppAutocompleteOption } from './app-autocomplete-option'; +import { type AppAutocompleteOptionContext } from './app-autocomplete-option-template.directive'; + +const LOAD_MORE_PREFETCH_PX = 240; + +@Component({ + selector: 'app-autocomplete-popup', + standalone: true, + imports: [NgTemplateOutlet, OverlayModule, ComboboxPopupContainer, Listbox, Option, TranslocoPipe, LucideLoaderCircle], + changeDetection: ChangeDetectionStrategy.OnPush, + template: ` + + +
+
    + @for (option of options(); track option.value) { +
  • + @if (optionTemplate(); as template) { + + } @else { + {{ option.label }} + } +
  • + } @empty { + @if (pending()) { +
  • + + {{ 'shared.ui.spinner.loading' | transloco }} +
  • + } @else if (errored()) { +
  • {{ 'shared.ui.autocomplete.loadFailed' | transloco }}
  • + } @else { +
  • {{ emptyMessage() || ('shared.ui.autocomplete.noResults' | transloco) }}
  • + } + } + @if (showLoadError()) { +
  • {{ 'shared.ui.autocomplete.loadFailed' | transloco }}
  • + } @else if (showSentinel()) { + + } +
+
+
+
+ `, +}) +export class AppAutocompletePopupComponent { + readonly origin = input.required | HTMLElement>(); + readonly open = input(false); + readonly disabled = input(false); + readonly readonly = input(false); + readonly pending = input(false); + readonly loadingMore = input(false); + readonly hasMore = input(false); + readonly errored = input(false); + readonly suggestions = input([]); + readonly emptyMessage = input(''); + readonly optionTemplate = input | null>(null); + + readonly optionSelected = output(); + readonly loadMore = output(); + + private readonly overlay = viewChild(CdkConnectedOverlay); + private readonly listbox = viewChild>(Listbox); + private readonly optionRefs = viewChildren>(Option); + private readonly listRef = viewChild>('list'); + private readonly sentinelRef = viewChild>('sentinel'); + private readonly overlayService = inject(Overlay); + + protected readonly overlayPositions: ConnectedPosition[] = connectedOverlayPositions; + protected readonly overlayScrollStrategy: ScrollStrategy = connectedOverlayScrollStrategy(this.overlayService); + protected readonly surfaceClass = cn(overlayListSurfaceClass, connectedOverlayPanelClass, 'box-border w-full p-0'); + protected readonly optionClass = cn(overlayListOptionClass, 'shrink-0'); + protected readonly emptyClass = overlayListEmptyItemClass; + protected readonly loadingRowClass = cn(overlayListEmptyItemClass, 'justify-center'); + protected readonly listClass = cn( + overlayListRootClass, + 'max-h-60 overflow-y-auto overscroll-contain p-1 [scrollbar-gutter:stable]', + ); + + protected readonly options = computed(() => { + const seen = new Set(); + return this.suggestions().filter((option) => { + if (seen.has(option.value)) return false; + seen.add(option.value); + return true; + }); + }); + protected readonly showSentinel = computed(() => this.hasMore() && this.options().length > 0); + protected readonly showLoadError = computed(() => this.errored() && this.options().length > 0 && !this.loadingMore()); + protected readonly isBusy = computed(() => this.pending() || this.loadingMore()); + private readonly loadMoreRequested = linkedSignal({ + source: () => ({ options: this.options(), loadingMore: this.loadingMore() }), + computation: () => false, + }); + private leadingOptionValue: string | null = null; + + constructor() { + effect((onCleanup) => { + this.options(); + const list = this.listRef()?.nativeElement; + const sentinel = this.sentinelRef()?.nativeElement; + if (!list || !sentinel) return; + + const observer = new IntersectionObserver( + (entries) => { + if (entries.some((entry) => entry.isIntersecting)) this.requestLoadMore(); + }, + { root: list, rootMargin: `0px 0px ${LOAD_MORE_PREFETCH_PX}px 0px` }, + ); + observer.observe(sentinel); + onCleanup(() => observer.disconnect()); + }); + + afterRenderEffect(() => { + const leading = this.options()[0]?.value ?? null; + this.pending(); + this.errored(); + this.showSentinel(); + + const list = this.listRef()?.nativeElement; + if (list && leading !== this.leadingOptionValue) list.scrollTop = 0; + this.leadingOptionValue = leading; + refreshConnectedOverlayPosition(this.overlay()); + }); + } + + activeOption(): AppAutocompleteOption | null { + const active = this.optionRefs().find((option) => option.active()); + if (!active) return null; + const value = active.value(); + return this.options().find((option) => option.value === value) ?? null; + } + + clearSelection(): void { + this.listbox()?.values.set([]); + } + + protected onOverlayAttach(): void { + refreshConnectedOverlayPosition(this.overlay()); + } + + protected onValuesChange(values: readonly string[] | Set): void { + const picked = this.lastSelectedValue(values); + if (!picked) return; + + this.clearSelection(); + const option = this.options().find((candidate) => candidate.value === picked); + if (option) this.optionSelected.emit(option); + } + + protected onOptionPointerdown(event: PointerEvent, option: AppAutocompleteOption): void { + event.preventDefault(); + event.stopPropagation(); + this.clearSelection(); + this.optionSelected.emit(option); + } + + private requestLoadMore(): void { + if ( + this.disabled() || + this.readonly() || + this.pending() || + this.loadingMore() || + this.errored() || + !this.hasMore() || + this.loadMoreRequested() + ) return; + + this.loadMoreRequested.set(true); + this.loadMore.emit(); + } + + private lastSelectedValue(values: readonly string[] | Set): string | null { + const selected = Array.isArray(values) ? values : [...values]; + return selected[selected.length - 1] ?? null; + } +} diff --git a/frontend/src/app/shared/ui/autocomplete/app-autocomplete-selected-tags.component.ts b/frontend/src/app/shared/ui/autocomplete/app-autocomplete-selected-tags.component.ts new file mode 100644 index 000000000..71c621f16 --- /dev/null +++ b/frontend/src/app/shared/ui/autocomplete/app-autocomplete-selected-tags.component.ts @@ -0,0 +1,31 @@ +import { ChangeDetectionStrategy, Component, input, output } from '@angular/core'; + +import { AppTagComponent } from '../tag/app-tag.component'; +import { type TagSize } from '../tag/app-tag.variants'; +import { type AppAutocompleteOption } from './app-autocomplete-option'; + +@Component({ + selector: 'app-autocomplete-selected-tags', + standalone: true, + imports: [AppTagComponent], + host: { class: 'contents' }, + changeDetection: ChangeDetectionStrategy.OnPush, + template: ` + @for (tag of tags(); track tag.value) { + + } + `, +}) +export class AppAutocompleteSelectedTagsComponent { + readonly tags = input([]); + readonly size = input('md'); + readonly removable = input(true); + readonly removeTagLabel = input(''); + + readonly remove = output(); +} diff --git a/frontend/src/app/shared/ui/autocomplete/app-autocomplete.component.ts b/frontend/src/app/shared/ui/autocomplete/app-autocomplete.component.ts index 8e352626e..dc08834cf 100644 --- a/frontend/src/app/shared/ui/autocomplete/app-autocomplete.component.ts +++ b/frontend/src/app/shared/ui/autocomplete/app-autocomplete.component.ts @@ -1,26 +1,19 @@ -import { ChangeDetectionStrategy, Component, linkedSignal, model } from '@angular/core'; +import { ChangeDetectionStrategy, Component, computed, input, linkedSignal, model, signal, viewChild } from '@angular/core'; import { type FormValueControl } from '@angular/forms/signals'; -import { Combobox, ComboboxInput, ComboboxPopupContainer } from '@angular/aria/combobox'; -import { Listbox, Option } from '@angular/aria/listbox'; -import { OverlayModule } from '@angular/cdk/overlay'; -import { TranslocoPipe } from '@jsverse/transloco'; +import { Combobox, ComboboxInput } from '@angular/aria/combobox'; import { LucideLoaderCircle } from '@lucide/angular'; import { AppAutocompleteBaseDirective } from './app-autocomplete-base.directive'; +import { type AppAutocompleteOption } from './app-autocomplete-option'; +import { AppAutocompletePopupComponent } from './app-autocomplete-popup.component'; +import { AppAutocompleteSelectedTagsComponent } from './app-autocomplete-selected-tags.component'; + +type AppAutocompleteSelectedDisplay = 'text' | 'tag'; @Component({ selector: 'app-autocomplete', standalone: true, - imports: [ - OverlayModule, - Combobox, - ComboboxInput, - ComboboxPopupContainer, - Listbox, - Option, - TranslocoPipe, - LucideLoaderCircle, - ], + imports: [Combobox, ComboboxInput, LucideLoaderCircle, AppAutocompletePopupComponent, AppAutocompleteSelectedTagsComponent], host: { class: 'block w-full' }, changeDetection: ChangeDetectionStrategy.OnPush, template: ` @@ -35,6 +28,14 @@ import { AppAutocompleteBaseDirective } from './app-autocomplete-base.directive' #origin [class]="boxClass()" (pointerdown)="focusInputOnPointerdown($event, input)"> + @if (selectedTags().length) { + + } - @if (pending()) { - - } + - - -
-
    - @for (option of suggestions(); track option) { -
  • - {{ option }} -
  • - } @empty { -
  • {{ emptyMessage() || ('shared.ui.autocomplete.noResults' | transloco) }}
  • - } -
-
-
-
+ `, }) export class AppAutocompleteComponent extends AppAutocompleteBaseDirective implements FormValueControl { readonly value = model(''); + readonly selectedDisplay = input('text'); + readonly removeTagLabel = input(''); - protected readonly query = linkedSignal(() => this.value()); + private readonly popup = viewChild(AppAutocompletePopupComponent); + private readonly committedOption = signal(null); + + protected readonly selectedLabel = computed(() => { + const value = this.value(); + const committed = this.committedOption(); + if (committed && committed.value === value) return committed.label; + return this.normalizedSuggestions().find((option) => option.value === value)?.label ?? value; + }); + + protected readonly query = linkedSignal({ + source: () => ({ display: this.selectedDisplay(), label: this.selectedLabel() }), + computation: ({ display, label }) => (display === 'tag' && label.trim() ? '' : label), + }); + protected readonly showSelectedTag = computed(() => this.selectedDisplay() === 'tag' && !!this.value().trim()); + protected readonly selectedTags = computed(() => + this.showSelectedTag() ? [{ value: this.value(), label: this.selectedLabel() }] : [], + ); + protected readonly inputReadonly = computed(() => this.readonly() || this.showSelectedTag()); + protected readonly placeholderText = computed(() => (this.showSelectedTag() ? '' : this.placeholder())); protected onType(text: string): void { - if (this.isUnavailable()) return; - if (this.allowCustom() || !text.trim()) this.value.set(text); + if (this.isUnavailable() || this.showSelectedTag()) return; + if (this.selectedDisplay() !== 'tag' && (this.allowCustom() || !text.trim())) this.value.set(text); this.complete.emit(text); } + protected onEnter(event: Event): void { + if (this.isUnavailable() || this.selectedDisplay() !== 'tag' || this.showSelectedTag()) return; + event.preventDefault(); + event.stopPropagation(); + const active = this.popup()?.activeOption(); + if (active) { + this.selectOption(active); + return; + } + const trimmed = this.query().trim(); + if (!trimmed) return; + const match = this.normalizedSuggestions().find((option) => option.label === trimmed); + if (match) { + this.selectOption(match); + return; + } + if (this.allowCustom()) this.selectOption({ value: trimmed, label: trimmed }); + } + + protected override onInputFocus(): void { + if (this.showSelectedTag()) return; + super.onInputFocus(); + } + protected onInputBlur(): void { this.touched.set(true); if (this.allowCustom()) return; queueMicrotask(() => { - if (!this.allowCustom()) this.query.set(this.value()); + if (!this.allowCustom()) this.query.set(this.selectedLabel()); }); } - protected onSelect(values: readonly string[]): void { - if (this.isUnavailable() || !values.length) return; - const picked = values[values.length - 1]; - this.value.set(picked); - this.query.set(picked); + protected selectOption(option: AppAutocompleteOption): void { + if (this.isUnavailable()) return; + this.committedOption.set(option); + this.value.set(option.value); + this.query.set(this.selectedDisplay() === 'tag' ? '' : option.label); this.touched.set(true); - this.combobox()?.close(); + this.closePopup(); + } + + protected clearSelectedTag(input: HTMLInputElement): void { + if (this.isUnavailable()) return; + this.committedOption.set(null); + this.value.set(''); + this.query.set(''); + this.touched.set(true); + this.complete.emit(''); + queueMicrotask(() => input.focus()); } } diff --git a/frontend/src/app/shared/ui/autocomplete/app-multi-autocomplete.component.ts b/frontend/src/app/shared/ui/autocomplete/app-multi-autocomplete.component.ts index 226016aa6..4e5dedc02 100644 --- a/frontend/src/app/shared/ui/autocomplete/app-multi-autocomplete.component.ts +++ b/frontend/src/app/shared/ui/autocomplete/app-multi-autocomplete.component.ts @@ -6,32 +6,20 @@ import { linkedSignal, model, viewChild, - viewChildren, } from '@angular/core'; import { type FormValueControl } from '@angular/forms/signals'; -import { Combobox, ComboboxInput, ComboboxPopupContainer } from '@angular/aria/combobox'; -import { Listbox, Option } from '@angular/aria/listbox'; -import { OverlayModule } from '@angular/cdk/overlay'; -import { TranslocoPipe } from '@jsverse/transloco'; +import { Combobox, ComboboxInput } from '@angular/aria/combobox'; import { LucideLoaderCircle } from '@lucide/angular'; -import { AppTagComponent } from '../tag/app-tag.component'; import { AppAutocompleteBaseDirective } from './app-autocomplete-base.directive'; +import { type AppAutocompleteOption } from './app-autocomplete-option'; +import { AppAutocompletePopupComponent } from './app-autocomplete-popup.component'; +import { AppAutocompleteSelectedTagsComponent } from './app-autocomplete-selected-tags.component'; @Component({ selector: 'app-multi-autocomplete', standalone: true, - imports: [ - OverlayModule, - Combobox, - ComboboxInput, - ComboboxPopupContainer, - Listbox, - Option, - AppTagComponent, - TranslocoPipe, - LucideLoaderCircle, - ], + imports: [Combobox, ComboboxInput, LucideLoaderCircle, AppAutocompletePopupComponent, AppAutocompleteSelectedTagsComponent], host: { class: 'block w-full' }, changeDetection: ChangeDetectionStrategy.OnPush, template: ` @@ -46,13 +34,13 @@ import { AppAutocompleteBaseDirective } from './app-autocomplete-base.directive' #origin [class]="boxClass()" (pointerdown)="focusInputOnPointerdown($event, input)"> - @for (tag of value(); track tag) { - + [removeTagLabel]="removeTagLabel()" + (remove)="removeChip($event)" /> } - @if (pending()) { - - } + - - -
-
    - @for (option of suggestions(); track option) { -
  • - {{ option }} -
  • - } @empty { -
  • {{ emptyMessage() || ('shared.ui.autocomplete.noResults' | transloco) }}
  • - } -
-
-
-
+ `, }) @@ -124,14 +96,20 @@ export class AppMultiAutocompleteComponent extends AppAutocompleteBaseDirective readonly removeTagLabel = input(''); - private readonly listbox = viewChild>(Listbox); - protected readonly optionRefs = viewChildren(Option); + private readonly popup = viewChild(AppAutocompletePopupComponent); + private readonly chipLabels = new Map(); protected readonly query = linkedSignal({ source: this.value, computation: () => '', }); + protected readonly selectedTags = computed(() => + this.value().map((value) => ({ + value, + label: this.chipLabels.get(value) ?? this.normalizedSuggestions().find((option) => option.value === value)?.label ?? value, + })), + ); protected readonly placeholderText = computed(() => (this.value().length ? '' : this.placeholder())); protected onType(text: string): void { @@ -143,12 +121,19 @@ export class AppMultiAutocompleteComponent extends AppAutocompleteBaseDirective if (this.isUnavailable()) return; event.preventDefault(); event.stopPropagation(); - const active = this.optionRefs().find((option) => option.active()); + const active = this.popup()?.activeOption(); if (active) { - this.addChip(String(active.value()), true); + this.addChip(active); return; } - this.addChip(this.query()); + const trimmed = this.query().trim(); + if (!trimmed) return; + const match = this.normalizedSuggestions().find((option) => option.label === trimmed); + if (match) { + this.addChip(match); + return; + } + if (this.allowCustom()) this.addChip({ value: trimmed, label: trimmed }); } protected onBackspace(): void { @@ -159,35 +144,33 @@ export class AppMultiAutocompleteComponent extends AppAutocompleteBaseDirective this.touched.set(true); } - protected onSelect(values: readonly string[]): void { - if (this.isUnavailable() || !values.length) return; - this.addChip(values[values.length - 1], true); + protected selectOption(option: AppAutocompleteOption): void { + this.addChip(option); } - protected removeChip(tag: string): void { - this.value.set(this.value().filter((existing) => existing !== tag)); + protected removeChip(value: string): void { + this.chipLabels.delete(value); + this.value.set(this.value().filter((existing) => existing !== value)); this.touched.set(true); } - private addChip(text: string, fromSuggestion = false): void { + private addChip(option: AppAutocompleteOption): void { if (this.isUnavailable()) return; - const trimmed = text.trim(); - if (!trimmed) return; - if (!fromSuggestion && !this.allowCustom() && !this.suggestions().includes(trimmed)) return; const current = this.value(); - if (current.includes(trimmed)) { + if (current.includes(option.value)) { this.clearTagInput(); return; } - this.value.set([...current, trimmed]); + this.chipLabels.set(option.value, option.label); + this.value.set([...current, option.value]); this.clearTagInput(); this.touched.set(true); this.complete.emit(''); } private clearTagInput(): void { - this.combobox()?.close(); - this.listbox()?.values.set([]); + this.closePopup(); + this.popup()?.clearSelection(); this.query.set(''); } } diff --git a/frontend/src/i18n/cs/shared.json b/frontend/src/i18n/cs/shared.json index fdbc67a76..4fc27be11 100644 --- a/frontend/src/i18n/cs/shared.json +++ b/frontend/src/i18n/cs/shared.json @@ -159,8 +159,7 @@ }, "ui": { "autocomplete": { - "noResults": "", - "removeTag": "" + "noResults": "" }, "datePicker": { "previousMonth": "", diff --git a/frontend/src/i18n/da/shared.json b/frontend/src/i18n/da/shared.json index e0bb31512..23dafb010 100644 --- a/frontend/src/i18n/da/shared.json +++ b/frontend/src/i18n/da/shared.json @@ -192,8 +192,7 @@ "loading": "" }, "autocomplete": { - "noResults": "", - "removeTag": "" + "noResults": "" }, "datePicker": { "nextMonth": "", diff --git a/frontend/src/i18n/de/shared.json b/frontend/src/i18n/de/shared.json index 4fe92b5f4..9125539f9 100644 --- a/frontend/src/i18n/de/shared.json +++ b/frontend/src/i18n/de/shared.json @@ -192,8 +192,7 @@ "loading": "" }, "autocomplete": { - "noResults": "", - "removeTag": "" + "noResults": "" }, "datePicker": { "nextMonth": "", diff --git a/frontend/src/i18n/en/shared.json b/frontend/src/i18n/en/shared.json index 7b256b021..8d0c2b659 100644 --- a/frontend/src/i18n/en/shared.json +++ b/frontend/src/i18n/en/shared.json @@ -160,7 +160,7 @@ "ui": { "autocomplete": { "noResults": "No results", - "removeTag": "Remove {{ tag }}" + "loadFailed": "Couldn't load results" }, "datePicker": { "previousMonth": "Previous month", diff --git a/frontend/src/i18n/es/shared.json b/frontend/src/i18n/es/shared.json index 7d703fb30..cece9ad6d 100644 --- a/frontend/src/i18n/es/shared.json +++ b/frontend/src/i18n/es/shared.json @@ -192,8 +192,7 @@ "loading": "" }, "autocomplete": { - "noResults": "", - "removeTag": "" + "noResults": "" }, "datePicker": { "nextMonth": "", diff --git a/frontend/src/i18n/fr/shared.json b/frontend/src/i18n/fr/shared.json index 85fe526db..d259fe020 100644 --- a/frontend/src/i18n/fr/shared.json +++ b/frontend/src/i18n/fr/shared.json @@ -192,8 +192,7 @@ "loading": "" }, "autocomplete": { - "noResults": "", - "removeTag": "" + "noResults": "" }, "datePicker": { "nextMonth": "", diff --git a/frontend/src/i18n/hr/shared.json b/frontend/src/i18n/hr/shared.json index 66080e4fb..e444573e6 100644 --- a/frontend/src/i18n/hr/shared.json +++ b/frontend/src/i18n/hr/shared.json @@ -192,8 +192,7 @@ "loading": "" }, "autocomplete": { - "noResults": "", - "removeTag": "" + "noResults": "" }, "datePicker": { "nextMonth": "", diff --git a/frontend/src/i18n/hu/shared.json b/frontend/src/i18n/hu/shared.json index e0bb31512..23dafb010 100644 --- a/frontend/src/i18n/hu/shared.json +++ b/frontend/src/i18n/hu/shared.json @@ -192,8 +192,7 @@ "loading": "" }, "autocomplete": { - "noResults": "", - "removeTag": "" + "noResults": "" }, "datePicker": { "nextMonth": "", diff --git a/frontend/src/i18n/id/shared.json b/frontend/src/i18n/id/shared.json index f879879cd..4f0397bcf 100644 --- a/frontend/src/i18n/id/shared.json +++ b/frontend/src/i18n/id/shared.json @@ -192,8 +192,7 @@ "loading": "" }, "autocomplete": { - "noResults": "", - "removeTag": "" + "noResults": "" }, "datePicker": { "nextMonth": "", diff --git a/frontend/src/i18n/it/shared.json b/frontend/src/i18n/it/shared.json index 83dd819e1..be26a0040 100644 --- a/frontend/src/i18n/it/shared.json +++ b/frontend/src/i18n/it/shared.json @@ -192,8 +192,7 @@ "loading": "" }, "autocomplete": { - "noResults": "", - "removeTag": "" + "noResults": "" }, "datePicker": { "nextMonth": "", diff --git a/frontend/src/i18n/ja/shared.json b/frontend/src/i18n/ja/shared.json index 300a84ae4..d36db51a3 100644 --- a/frontend/src/i18n/ja/shared.json +++ b/frontend/src/i18n/ja/shared.json @@ -192,8 +192,7 @@ "loading": "" }, "autocomplete": { - "noResults": "", - "removeTag": "" + "noResults": "" }, "datePicker": { "nextMonth": "", diff --git a/frontend/src/i18n/ko/shared.json b/frontend/src/i18n/ko/shared.json index fdbc67a76..4fc27be11 100644 --- a/frontend/src/i18n/ko/shared.json +++ b/frontend/src/i18n/ko/shared.json @@ -159,8 +159,7 @@ }, "ui": { "autocomplete": { - "noResults": "", - "removeTag": "" + "noResults": "" }, "datePicker": { "previousMonth": "", diff --git a/frontend/src/i18n/nl/shared.json b/frontend/src/i18n/nl/shared.json index 87dd3d589..3510c5b49 100644 --- a/frontend/src/i18n/nl/shared.json +++ b/frontend/src/i18n/nl/shared.json @@ -192,8 +192,7 @@ "loading": "" }, "autocomplete": { - "noResults": "", - "removeTag": "" + "noResults": "" }, "datePicker": { "nextMonth": "", diff --git a/frontend/src/i18n/pl/shared.json b/frontend/src/i18n/pl/shared.json index f56d6dc31..bb9ac4bf4 100644 --- a/frontend/src/i18n/pl/shared.json +++ b/frontend/src/i18n/pl/shared.json @@ -192,8 +192,7 @@ "loading": "" }, "autocomplete": { - "noResults": "", - "removeTag": "" + "noResults": "" }, "datePicker": { "nextMonth": "", diff --git a/frontend/src/i18n/pt/shared.json b/frontend/src/i18n/pt/shared.json index 49fa2b4ac..f308aec10 100644 --- a/frontend/src/i18n/pt/shared.json +++ b/frontend/src/i18n/pt/shared.json @@ -192,8 +192,7 @@ "loading": "" }, "autocomplete": { - "noResults": "", - "removeTag": "" + "noResults": "" }, "datePicker": { "nextMonth": "", diff --git a/frontend/src/i18n/ru/shared.json b/frontend/src/i18n/ru/shared.json index 397f1941d..d7ea8cf38 100644 --- a/frontend/src/i18n/ru/shared.json +++ b/frontend/src/i18n/ru/shared.json @@ -192,8 +192,7 @@ "loading": "" }, "autocomplete": { - "noResults": "", - "removeTag": "" + "noResults": "" }, "datePicker": { "nextMonth": "", diff --git a/frontend/src/i18n/sk/shared.json b/frontend/src/i18n/sk/shared.json index 792638a18..639cac231 100644 --- a/frontend/src/i18n/sk/shared.json +++ b/frontend/src/i18n/sk/shared.json @@ -192,8 +192,7 @@ "loading": "" }, "autocomplete": { - "noResults": "", - "removeTag": "" + "noResults": "" }, "datePicker": { "nextMonth": "", diff --git a/frontend/src/i18n/sl/shared.json b/frontend/src/i18n/sl/shared.json index 99ed87c3b..281c2e20c 100644 --- a/frontend/src/i18n/sl/shared.json +++ b/frontend/src/i18n/sl/shared.json @@ -192,8 +192,7 @@ "loading": "" }, "autocomplete": { - "noResults": "", - "removeTag": "" + "noResults": "" }, "datePicker": { "nextMonth": "", diff --git a/frontend/src/i18n/sv/shared.json b/frontend/src/i18n/sv/shared.json index 45aa685fd..3d1ed96a3 100644 --- a/frontend/src/i18n/sv/shared.json +++ b/frontend/src/i18n/sv/shared.json @@ -192,8 +192,7 @@ "loading": "" }, "autocomplete": { - "noResults": "", - "removeTag": "" + "noResults": "" }, "datePicker": { "nextMonth": "", diff --git a/frontend/src/i18n/uk/shared.json b/frontend/src/i18n/uk/shared.json index fb580bbdc..90fc0b51d 100644 --- a/frontend/src/i18n/uk/shared.json +++ b/frontend/src/i18n/uk/shared.json @@ -192,8 +192,7 @@ "loading": "" }, "autocomplete": { - "noResults": "", - "removeTag": "" + "noResults": "" }, "datePicker": { "nextMonth": "", diff --git a/frontend/src/i18n/zh/shared.json b/frontend/src/i18n/zh/shared.json index b275c7606..4b22dbaef 100644 --- a/frontend/src/i18n/zh/shared.json +++ b/frontend/src/i18n/zh/shared.json @@ -192,8 +192,7 @@ "loading": "" }, "autocomplete": { - "noResults": "", - "removeTag": "" + "noResults": "" }, "datePicker": { "nextMonth": "",