diff --git a/frontend/src/app/shared/components/dropdown/dropdown.component.html b/frontend/src/app/shared/components/dropdown/dropdown.component.html index 5a0523f..d97f7d5 100644 --- a/frontend/src/app/shared/components/dropdown/dropdown.component.html +++ b/frontend/src/app/shared/components/dropdown/dropdown.component.html @@ -25,7 +25,7 @@ stroke-width="1.5" stroke="currentColor" class="size-6 cursor-pointer" - (click)="toggleDropdown()" + (click)="toggleDropdown($event)" [class.rotate-180]="showDropdown()"> - item.toLowerCase().includes(value.toLowerCase()) - ); - - this.filteredItems.set(matchingItems); + this.updateFilteredItems(); const exactMatch = this.items().find( (item) => item.toLowerCase() === value.toLowerCase() @@ -148,8 +155,7 @@ export class DropdownComponent implements ControlValueAccessor, Validator { this.itemSelected.emit(''); } - this.showDropdown.set(matchingItems.length > 0 || value.trim() !== ''); - + this.showDropdown.set(true); this.onTouched(); } @@ -207,21 +213,33 @@ export class DropdownComponent implements ControlValueAccessor, Validator { } public onFocus(): void { - this.filteredItems.set(this.items()); + this.showDropdown.set(true); + this.updateFilteredItems(); this.markAsTouched(); } public onBlur(): void { - if (!this.isMouseInDropdown()) { - this.closeDropdown(); - this.markAsTouched(); - } + setTimeout(() => { + if (!this.isMouseInDropdown()) { + this.closeDropdown(); + this.markAsTouched(); + } + }, 1); } private isValidOption(value: string): boolean { return this.items().includes(value); } + private updateFilteredItems(): void { + const searchTerm = this.searchTerm().toLowerCase(); + const matchingItems = this.items().filter((item) => + item.toLowerCase().includes(searchTerm) + ); + + this.filteredItems.set(matchingItems); + } + private onChange: (value: string) => void = () => {}; private onTouched: () => void = () => {}; }