Skip to content

Commit

Permalink
Merge pull request #677 from geonetwork/DH-focus-search-field-on-app-…
Browse files Browse the repository at this point in the history
…load

feat(libs): Focus search field on app load
  • Loading branch information
Angi-Kinas authored Nov 13, 2023
2 parents 54ff36a + f360092 commit 1c1919e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<gn-ui-fuzzy-search
class="text-[18px] pointer-events-auto"
(itemSelected)="onFuzzySearchSelection($event)"
[autoFocus]="true"
></gn-ui-fuzzy-search>
<div class="flex h-0 py-5 gap-3" [style.opacity]="-0.6 + expandRatio * 2">
<datahub-header-badge-button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
(inputCleared)="handleInputCleared()"
[value]="searchInputValue$ | async"
[clearOnSelection]="true"
[autoFocus]="autoFocus"
></gn-ui-autocomplete>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
ChangeDetectionStrategy,
Component,
EventEmitter,
Input,
OnInit,
Output,
ViewChild,
Expand All @@ -25,6 +26,7 @@ import { RecordsRepositoryInterface } from '@geonetwork-ui/common/domain/records
})
export class FuzzySearchComponent implements OnInit {
@ViewChild(AutocompleteComponent) autocomplete: AutocompleteComponent
@Input() autoFocus = false
@Output() itemSelected = new EventEmitter<CatalogRecord>()
@Output() inputSubmitted = new EventEmitter<string>()
searchInputValue$: Observable<{ title: string }>
Expand Down
7 changes: 7 additions & 0 deletions libs/ui/inputs/src/lib/autocomplete/autocomplete.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
AfterViewInit,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef,
EventEmitter,
Expand Down Expand Up @@ -47,6 +48,7 @@ export class AutocompleteComponent
@Input() action: (value: string) => Observable<AutocompleteItem[]>
@Input() value?: AutocompleteItem
@Input() clearOnSelection = false
@Input() autoFocus = false
@Output() itemSelected = new EventEmitter<AutocompleteItem>()
@Output() inputSubmitted = new EventEmitter<string>()
@Output() inputCleared = new EventEmitter<void>()
Expand All @@ -65,6 +67,7 @@ export class AutocompleteComponent

@Input() displayWithFn: (AutocompleteItem) => string = (item) => item

constructor(private cdRef: ChangeDetectorRef) {}
ngOnChanges(changes: SimpleChanges): void {
const { value } = changes
if (value) {
Expand Down Expand Up @@ -110,6 +113,10 @@ export class AutocompleteComponent

ngAfterViewInit(): void {
this.autocomplete.optionSelected.subscribe(this.selectionSubject)
if (this.autoFocus) {
this.inputRef.nativeElement.focus()
this.cdRef.detectChanges()
}
}

ngOnDestroy(): void {
Expand Down

0 comments on commit 1c1919e

Please sign in to comment.