From cbcdf5de835211300fcd9b7a3f0c2f96b17f3377 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Sun, 1 Jul 2018 15:36:07 -0400 Subject: [PATCH] LP#1775466 Typeahead arrow icons Signed-off-by: Bill Erickson --- .../app/share/typeahead/typeahead.component.html | 27 ++++++++++------- .../src/app/share/typeahead/typeahead.component.ts | 35 ++++++++++++++-------- 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/typeahead/typeahead.component.html b/Open-ILS/src/eg2/src/app/share/typeahead/typeahead.component.html index ab48238d37..c47430a12f 100644 --- a/Open-ILS/src/eg2/src/app/share/typeahead/typeahead.component.html +++ b/Open-ILS/src/eg2/src/app/share/typeahead/typeahead.component.html @@ -4,14 +4,19 @@ {{r.label}} - +
+ +
+ keyboard_arrow_up + keyboard_arrow_down +
+
diff --git a/Open-ILS/src/eg2/src/app/share/typeahead/typeahead.component.ts b/Open-ILS/src/eg2/src/app/share/typeahead/typeahead.component.ts index 3db99dd768..98e9047ef4 100644 --- a/Open-ILS/src/eg2/src/app/share/typeahead/typeahead.component.ts +++ b/Open-ILS/src/eg2/src/app/share/typeahead/typeahead.component.ts @@ -1,4 +1,4 @@ -import {Component, OnInit, Input, Output, ViewChild, EventEmitter} from '@angular/core'; +import {Component, OnInit, Input, Output, ViewChild, EventEmitter, ElementRef} from '@angular/core'; import {Observable} from 'rxjs/Observable'; import {map} from 'rxjs/operators/map'; import {mapTo} from 'rxjs/operators/mapTo'; @@ -18,7 +18,11 @@ export interface TypeaheadEntry { @Component({ selector: 'eg-typeahead', - templateUrl: './typeahead.component.html' + templateUrl: './typeahead.component.html', + styles: [` + .icons {margin-left:-18px} + .material-icons {font-size: 16px;font-weight:bold} + `] }) export class TypeaheadComponent implements OnInit { @@ -45,34 +49,41 @@ export class TypeaheadComponent implements OnInit { this.entrylist = el; } - // Emitted when the org unit value is changed via the selector. - // Does not fire on initialOrg + // Emitted when the value is changed via UI. @Output() onChange: EventEmitter; - // Useful for massaging the match string prior to comparison - // Default version trims leading/trailing spaces + // Useful for massaging the match string prior to comparison + // and display. Default version trims leading/trailing spaces. formatDisplayString: (TypeaheadEntry) => string; constructor( + private elm: ElementRef, private store: StoreService, ) { this.entrylist = []; this.click$ = new Subject(); this.onChange = new EventEmitter(); + + this.formatDisplayString = (result: TypeaheadEntry) => { + return result.label.trim(); + }; } ngOnInit() { - if (this.startId) { this.selected = this.entrylist.filter( e => e.id === this.startId)[0]; } + } - this.formatDisplayString = (result: TypeaheadEntry) => { - return result.label.trim(); - }; + openMe($event) { + // Give the input a chance to focus then fire the click + // handler to force open the typeahead + this.elm.nativeElement.getElementsByTagName('input')[0].focus(); + setTimeout(() => this.click$.next('')); } + // Fired by the typeahead to inform us of a change. // TODO: this does not fire when the value is cleared :( -- implement // change detection on this.selected to look specifically for NULL. @@ -88,7 +99,8 @@ export class TypeaheadComponent implements OnInit { merge( // Inject a specifier indicating the source of the // action is a user click instead of a text entry. - this.click$.pipe(filter(() => !this.instance.isPopupOpen())) + this.click$ + .pipe(filter(() => !this.instance.isPopupOpen())) .pipe(map(nothing => { if (this.clickShowsAll) { return '_CLICK_'; @@ -99,7 +111,6 @@ export class TypeaheadComponent implements OnInit { ), map(term => { - if (term === '' || term === '_CLICK_') { // Click events display all visible entrylist return this.entrylist; -- 2.11.0