@@ -5,12 +5,12 @@ import {Typeahead} from './typeahead.directive';
55import { TypeaheadOptions } from './typeahead-options.class' ;
66import { positionService } from '../position' ;
77import { Ng2BootstrapConfig , Ng2BootstrapTheme } from '../ng2-bootstrap-config' ;
8-
98const TEMPLATE :any = {
109 [ Ng2BootstrapTheme . BS4 ] : `
1110 <div class="dropdown-menu"
11+ style="display: block"
1212 [ngStyle]="{top: top, left: left, display: display}"
13- style="display: block ">
13+ (mouseleave)="focusLost() ">
1414 <a href="#"
1515 *ngFor="#match of matches"
1616 class="dropdown-item"
@@ -22,8 +22,9 @@ const TEMPLATE:any = {
2222 ` ,
2323 [ Ng2BootstrapTheme . BS3 ] : `
2424 <ul class="dropdown-menu"
25+ style="display: block"
2526 [ngStyle]="{top: top, left: left, display: display}"
26- style="display: block ">
27+ (mouseleave)="focusLost() ">
2728 <li *ngFor="#match of matches"
2829 [class.active]="isActive(match)"
2930 (mouseenter)="selectActive(match)">
@@ -32,7 +33,6 @@ const TEMPLATE:any = {
3233 </ul>
3334 `
3435} ;
35-
3636@Component ( {
3737 selector : 'typeahead-container' ,
3838 directives : [ CORE_DIRECTIVES ] ,
@@ -43,9 +43,10 @@ export class TypeaheadContainer {
4343 public parent :Typeahead ;
4444 public query :any ;
4545 public element :ElementRef ;
46+ public isFocused :boolean = false ;
47+ private _active :any ;
4648 private _matches :Array < any > = [ ] ;
4749 private _field :string ;
48- private _active :any ;
4950 private top :string ;
5051 private left :string ;
5152 private display :string ;
@@ -62,7 +63,6 @@ export class TypeaheadContainer {
6263
6364 public set matches ( value :Array < string > ) {
6465 this . _matches = value ;
65-
6666 if ( this . _matches . length > 0 ) {
6767 this . _active = this . _matches [ 0 ] ;
6868 }
@@ -103,6 +103,7 @@ export class TypeaheadContainer {
103103 }
104104
105105 protected selectActive ( value :any ) :void {
106+ this . isFocused = true ;
106107 this . _active = value ;
107108 }
108109
@@ -115,7 +116,6 @@ export class TypeaheadContainer {
115116 : itemStr ) . toLowerCase ( ) ;
116117 let startIdx :number ;
117118 let tokenLen :number ;
118-
119119 // Replaces the capture string with the same string inside of a "strong" tag
120120 if ( typeof query === 'object' ) {
121121 let queryLen :number = query . length ;
@@ -136,7 +136,6 @@ export class TypeaheadContainer {
136136 itemStr = itemStr . substring ( 0 , startIdx ) + '<strong>' + itemStr . substring ( startIdx , startIdx + tokenLen ) + '</strong>' + itemStr . substring ( startIdx + tokenLen ) ;
137137 }
138138 }
139-
140139 return itemStr ;
141140 }
142141
@@ -149,11 +148,14 @@ export class TypeaheadContainer {
149148 e . stopPropagation ( ) ;
150149 e . preventDefault ( ) ;
151150 }
152-
153151 this . parent . changeModel ( value ) ;
154152 this . parent . typeaheadOnSelect . emit ( {
155153 item : value
156154 } ) ;
157155 return false ;
158156 }
157+
158+ private focusLost ( ) :void {
159+ this . isFocused = false ;
160+ }
159161}
0 commit comments