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