mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-07-28 23:04:56 +00:00
Fix: fix Enter selection in search autocomplete (#13361)
This commit is contained in:
@@ -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 ')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user