Remove ngbdropdown keyboard events workaround

This commit is contained in:
shamoon 2024-05-10 12:56:03 -07:00
parent 18e78964f3
commit 654c4c867c
3 changed files with 7 additions and 21 deletions

View File

@ -10,7 +10,8 @@
spellcheck="false"
[(ngModel)]="query"
(ngModelChange)="this.queryDebounce.next($event)"
(keydown)="searchInputKeyDown($event)">
(keydown)="searchInputKeyDown($event)"
ngbDropdownAnchor>
<div class="position-absolute top-50 end-0 translate-middle">
@if (loading) {
<div class="spinner-border spinner-border-sm text-muted mt-1"></div>

View File

@ -475,13 +475,6 @@ describe('GlobalSearchComponent', () => {
expect(focusSpy).toHaveBeenCalled()
})
it('should prevent event propagation for keyboard events on buttons that are not arrows', () => {
const event = { stopImmediatePropagation: jest.fn(), key: 'Enter' }
const stopPropagationSpy = jest.spyOn(event, 'stopImmediatePropagation')
component.onButtonKeyDown(event as any)
expect(stopPropagationSpy).toHaveBeenCalled()
})
it('should support explicit advanced search', () => {
const qfSpy = jest.spyOn(documentListViewService, 'quickFilter')
component.query = 'test'

View File

@ -88,7 +88,7 @@ export class GlobalSearchComponent implements OnInit {
})
}
ngOnInit() {
public ngOnInit() {
this.hotkeyService
.addShortcut({ keys: '/', description: $localize`Global search` })
.subscribe(() => {
@ -241,7 +241,7 @@ export class GlobalSearchComponent implements OnInit {
item.nativeElement.focus()
}
onItemHover(event: MouseEvent) {
public onItemHover(event: MouseEvent) {
const item: ElementRef = this.resultItems
.toArray()
.find((item) => item.nativeElement === event.currentTarget)
@ -249,7 +249,7 @@ export class GlobalSearchComponent implements OnInit {
this.setCurrentItem()
}
onButtonHover(event: MouseEvent) {
public onButtonHover(event: MouseEvent) {
;(event.currentTarget as HTMLElement).focus()
}
@ -289,7 +289,7 @@ export class GlobalSearchComponent implements OnInit {
}
}
dropdownKeyDown(event: KeyboardEvent) {
public dropdownKeyDown(event: KeyboardEvent) {
if (
this.searchResults?.total &&
this.resultsDropdown.isOpen() &&
@ -332,18 +332,10 @@ export class GlobalSearchComponent implements OnInit {
}
}
onButtonKeyDown(event: KeyboardEvent) {
public onButtonKeyDown(event: KeyboardEvent) {
if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {
event.target.dispatchEvent(new MouseEvent('click', { ctrlKey: true }))
}
// prevents ngBootstrap issue with keydown events
if (
!['ArrowDown', 'ArrowUp', 'ArrowRight', 'ArrowLeft', 'Escape'].includes(
event.key
)
) {
event.stopImmediatePropagation()
}
}
public onDropdownOpenChange(open: boolean) {