From a68c487d604de6785384bdc5d09247d7a9de6d91 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon, 27 Jul 2026 23:33:13 -0700 Subject: [PATCH] Fix: fix Enter selection in search autocomplete (#13361) --- .../filter-editor.component.spec.ts | 30 +++++++++++++++++++ .../filter-editor/filter-editor.component.ts | 4 +++ 2 files changed, 34 insertions(+) diff --git a/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.spec.ts b/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.spec.ts index 7cc8f3638..1cf05b781 100644 --- a/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.spec.ts +++ b/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.spec.ts @@ -2269,4 +2269,34 @@ describe('FilterEditorComponent', () => { component.itemSelected({ item: 'world', preventDefault: () => true }) expect(component.textFilter).toEqual('hello world ') }) + + it('should choose the active autocomplete item with Enter', () => { + component.textFilterTarget = 'fulltext-query' + jest + .spyOn(searchService, 'autocomplete') + .mockReturnValue(of(['hello', 'help'])) + + const input = component.textFilterInput.nativeElement as HTMLInputElement + input.value = 'he' + input.dispatchEvent(new Event('input')) + tick(250) + + input.dispatchEvent( + new KeyboardEvent('keydown', { + key: 'ArrowDown', + bubbles: true, + cancelable: true, + }) + ) + input.dispatchEvent( + new KeyboardEvent('keydown', { + key: 'Enter', + bubbles: true, + cancelable: true, + }) + ) + fixture.detectChanges() + + expect(component.textFilter).toEqual('help ') + }) }) diff --git a/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.ts b/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.ts index 5566f9ecd..d747002b2 100644 --- a/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.ts +++ b/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.ts @@ -1314,6 +1314,10 @@ export class FilterEditorComponent textFilterKeydown(event: KeyboardEvent) { if (event.key == 'Enter') { + if (event.defaultPrevented) { + // NgbTypeahead calls preventDefault, so use that to detect if the Enter key was for the dropdown + return + } const filterString = ( this.textFilterInput.nativeElement as HTMLInputElement ).value