Always show advanced search button, open search on enter
This commit is contained in:
parent
7983487430
commit
e739f8b4a0
@ -6,15 +6,18 @@
|
|||||||
<div class="form-control form-control-sm">
|
<div class="form-control form-control-sm">
|
||||||
<input class="bg-transparent border-0 w-100 h-100" #searchInput type="text" name="query"
|
<input class="bg-transparent border-0 w-100 h-100" #searchInput type="text" name="query"
|
||||||
placeholder="Search" aria-label="Search" i18n-placeholder
|
placeholder="Search" aria-label="Search" i18n-placeholder
|
||||||
autocomplete="off" spellcheck="false"
|
autocomplete="off"
|
||||||
[(ngModel)]="query" (ngModelChange)="this.queryDebounce.next($event)" (keydown)="searchInputKeyDown($event)">
|
spellcheck="false"
|
||||||
|
[(ngModel)]="query"
|
||||||
|
(ngModelChange)="this.queryDebounce.next($event)"
|
||||||
|
(keydown)="searchInputKeyDown($event)">
|
||||||
<div class="position-absolute top-50 end-0 translate-middle">
|
<div class="position-absolute top-50 end-0 translate-middle">
|
||||||
@if (loading) {
|
@if (loading) {
|
||||||
<div class="spinner-border spinner-border-sm text-muted mt-1"></div>
|
<div class="spinner-border spinner-border-sm text-muted mt-1"></div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@if (query && (searchResults?.documents.length === searchService.searchResultObjectLimit || searchService.searchDbOnly)) {
|
@if (query) {
|
||||||
<button class="btn btn-sm btn-outline-secondary" type="button" (click)="runAdvanedSearch()">
|
<button class="btn btn-sm btn-outline-secondary" type="button" (click)="runAdvanedSearch()">
|
||||||
<ng-container i18n>Advanced search</ng-container>
|
<ng-container i18n>Advanced search</ng-container>
|
||||||
<i-bs width="1em" height="1em" name="arrow-right-short"></i-bs>
|
<i-bs width="1em" height="1em" name="arrow-right-short"></i-bs>
|
||||||
|
@ -260,6 +260,13 @@ describe('GlobalSearchComponent', () => {
|
|||||||
const closeSpy = jest.spyOn(component.resultsDropdown, 'close')
|
const closeSpy = jest.spyOn(component.resultsDropdown, 'close')
|
||||||
component.dropdownKeyDown(new KeyboardEvent('keydown', { key: 'Escape' }))
|
component.dropdownKeyDown(new KeyboardEvent('keydown', { key: 'Escape' }))
|
||||||
expect(closeSpy).toHaveBeenCalled()
|
expect(closeSpy).toHaveBeenCalled()
|
||||||
|
|
||||||
|
component.searchResults = searchResults as any
|
||||||
|
component.resultsDropdown.open()
|
||||||
|
component.query = 'test'
|
||||||
|
const advancedSearchSpy = jest.spyOn(component, 'runAdvanedSearch')
|
||||||
|
component.searchInputKeyDown(new KeyboardEvent('keydown', { key: 'Enter' }))
|
||||||
|
expect(advancedSearchSpy).toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should search on query debounce', fakeAsync(() => {
|
it('should search on query debounce', fakeAsync(() => {
|
||||||
|
@ -262,19 +262,16 @@ export class GlobalSearchComponent implements OnInit {
|
|||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
this.currentItemIndex = this.searchResults.total - 1
|
this.currentItemIndex = this.searchResults.total - 1
|
||||||
this.setCurrentItem()
|
this.setCurrentItem()
|
||||||
} else if (
|
} else if (event.key === 'Enter') {
|
||||||
event.key === 'Enter' &&
|
if (this.searchResults?.total === 1 && this.resultsDropdown.isOpen()) {
|
||||||
this.searchResults?.total === 1 &&
|
|
||||||
this.resultsDropdown.isOpen()
|
|
||||||
) {
|
|
||||||
this.primaryButtons.first.nativeElement.click()
|
this.primaryButtons.first.nativeElement.click()
|
||||||
this.searchInput.nativeElement.blur()
|
this.searchInput.nativeElement.blur()
|
||||||
} else if (
|
} else if (this.searchResults?.total && !this.resultsDropdown.isOpen()) {
|
||||||
event.key === 'Enter' &&
|
|
||||||
this.searchResults?.total &&
|
|
||||||
!this.resultsDropdown.isOpen()
|
|
||||||
) {
|
|
||||||
this.resultsDropdown.open()
|
this.resultsDropdown.open()
|
||||||
|
} else if (this.query?.length) {
|
||||||
|
this.runAdvanedSearch()
|
||||||
|
this.reset(true)
|
||||||
|
}
|
||||||
} else if (event.key === 'Escape' && !this.resultsDropdown.isOpen()) {
|
} else if (event.key === 'Escape' && !this.resultsDropdown.isOpen()) {
|
||||||
if (this.query?.length) {
|
if (this.query?.length) {
|
||||||
this.reset(true)
|
this.reset(true)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user