From 1c70f884821f51b504c669c8b026b25acaf6f821 Mon Sep 17 00:00:00 2001 From: Bastian Rihm Date: Fri, 29 Sep 2023 13:11:48 +0200 Subject: [PATCH] Fix search selection option focus (#2842) --- .../base-search-selector.component.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/client/src/app/ui/modules/search-selector/components/base-search-selector/base-search-selector.component.ts b/client/src/app/ui/modules/search-selector/components/base-search-selector/base-search-selector.component.ts index 83b7f2a169..b7802dfff9 100644 --- a/client/src/app/ui/modules/search-selector/components/base-search-selector/base-search-selector.component.ts +++ b/client/src/app/ui/modules/search-selector/components/base-search-selector/base-search-selector.component.ts @@ -210,6 +210,7 @@ export abstract class BaseSearchSelectorComponent extends BaseFormFieldControlCo } this._selectableItemsList = this.sortFn ? allItems.sort(this.sortFn) : allItems; this.filteredItemsSubject.next(this.getFilteredItemsBySearchValue()); + this.updateOptionFocus(); } protected get selectableItems(): Selectable[] { @@ -251,6 +252,15 @@ export abstract class BaseSearchSelectorComponent extends BaseFormFieldControlCo document.body.appendChild(sheet); } + private updateOptionFocus(): void { + setTimeout(() => { + if (!this.matSelect?.options.some(o => o.active)) { + this.matSelect.options.first.focus(); + this.matSelect.options.first.setActiveStyles(); + } + }, 200); + } + public onChipRemove(itemId: Id): void { this.addOrRemoveId(itemId); @@ -332,6 +342,7 @@ export abstract class BaseSearchSelectorComponent extends BaseFormFieldControlCo protected onSearchValueUpdated(nextValue: string): void { this.filteredItemsSubject.next(this.getFilteredItemsBySearchValue(nextValue.toLowerCase())); + this.updateOptionFocus(); } protected initializeForm(): void {