Merge pull request #2547 from mempool/simon/search-bar-click-outside
Click to close search dropdown
This commit is contained in:
		
						commit
						5e5daca600
					
				| @ -2,9 +2,7 @@ | ||||
|   <div class="d-flex"> | ||||
|     <div class="search-box-container mr-2"> | ||||
|       <input (focus)="focus$.next($any($event).target.value)" (click)="click$.next($any($event).target.value)" formControlName="searchText" type="text" class="form-control" i18n-placeholder="search-form.searchbar-placeholder" placeholder="Explore the full Bitcoin ecosystem"> | ||||
|        | ||||
|       <app-search-results #searchResults [results]="typeAhead$ | async" (selectedResult)="selectedResult($event)"></app-search-results> | ||||
|      | ||||
|       <app-search-results #searchResults [hidden]="dropdownHidden" [results]="typeAhead$ | async" (selectedResult)="selectedResult($event)"></app-search-results> | ||||
|     </div> | ||||
|     <div> | ||||
|       <button [disabled]="isSearching" type="submit" class="btn btn-block btn-primary"> | ||||
|  | ||||
| @ -1,4 +1,4 @@ | ||||
| import { Component, OnInit, ChangeDetectionStrategy, EventEmitter, Output, ViewChild, HostListener } from '@angular/core'; | ||||
| import { Component, OnInit, ChangeDetectionStrategy, EventEmitter, Output, ViewChild, HostListener, ElementRef } from '@angular/core'; | ||||
| import { FormBuilder, FormGroup, Validators } from '@angular/forms'; | ||||
| import { Router } from '@angular/router'; | ||||
| import { AssetsService } from '../../services/assets.service'; | ||||
| @ -23,6 +23,16 @@ export class SearchFormComponent implements OnInit { | ||||
|   isTypeaheading$ = new BehaviorSubject<boolean>(false); | ||||
|   typeAhead$: Observable<any>; | ||||
|   searchForm: FormGroup; | ||||
|   dropdownHidden = false; | ||||
| 
 | ||||
|   @HostListener('document:click', ['$event']) | ||||
|   onDocumentClick(event) { | ||||
|     if (this.elementRef.nativeElement.contains(event.target)) { | ||||
|       this.dropdownHidden = false; | ||||
|     } else { | ||||
|       this.dropdownHidden = true; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   regexAddress = /^([a-km-zA-HJ-NP-Z1-9]{26,35}|[a-km-zA-HJ-NP-Z1-9]{80}|[A-z]{2,5}1[a-zA-HJ-NP-Z0-9]{39,59})$/; | ||||
|   regexBlockhash = /^[0]{8}[a-fA-F0-9]{56}$/; | ||||
| @ -45,6 +55,7 @@ export class SearchFormComponent implements OnInit { | ||||
|     private electrsApiService: ElectrsApiService, | ||||
|     private apiService: ApiService, | ||||
|     private relativeUrlPipe: RelativeUrlPipe, | ||||
|     private elementRef: ElementRef, | ||||
|   ) { } | ||||
| 
 | ||||
|   ngOnInit(): void { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user