Skip to content

Commit

Permalink
feat(typeahead): fix for bs4-alfa.6 template
Browse files Browse the repository at this point in the history
fixes #1494
  • Loading branch information
valorkin committed Jan 13, 2017
1 parent 77d79ab commit 3fb6e38
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion demo/src/index-bs4.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<link href="https://fonts.googleapis.com/css?family=Roboto:400,300,700" rel="stylesheet" type="text/css">

<!--link to bootstrap.css v4.0.0-alpha-->
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" rel="stylesheet">
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet">
<!--<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/bootstrap.css">-->
<link rel="stylesheet" href="assets/css/glyphicons.css">
<link rel="stylesheet" href="assets/css/style.css">
Expand Down
2 changes: 2 additions & 0 deletions demo/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<!--<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">-->

<!--link to bootstrap.css-->
<!--<script>window.__theme = 'bs4';</script>-->
<!--<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet">-->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/style.css">
<link rel="stylesheet" href="assets/css/prettify-angulario.css">
Expand Down
44 changes: 24 additions & 20 deletions src/typeahead/typeahead-container.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
Component, ElementRef, TemplateRef, ViewEncapsulation
Component, ElementRef, TemplateRef, ViewEncapsulation, HostListener
} from '@angular/core';
import { isBs3 } from '../utils/ng2-bootstrap-config';
import { TypeaheadUtils } from './typeahead-utils';
Expand All @@ -10,8 +10,7 @@ import { TypeaheadMatch } from './typeahead-match.class';
selector: 'typeahead-container',
// tslint:disable-next-line
template: `
<template [ngIf]="!isBs4"><ul class="dropdown-menu"
(mouseleave)="focusLost()">
<template [ngIf]="!isBs4"><ul class="dropdown-menu">
<template ngFor let-match let-i="index" [ngForOf]="matches">
<li *ngIf="match.isHeader()" class="dropdown-header">{{match}}</li>
<li *ngIf="!match.isHeader()"
Expand All @@ -33,34 +32,38 @@ import { TypeaheadMatch } from './typeahead-match.class';
</li>
</template>
</ul></template>
<template [ngIf]="isBs4"><div class="dropdown-menu"
(mouseleave)="focusLost()">
<template [ngIf]="isBs4">
<template ngFor let-match let-i="index" [ngForOf]="matches">
<h6 *ngIf="match.isHeader()" class="dropdown-header">{{match}}</h6>
<div *ngIf="!match.isHeader() && !itemTemplate">
<a href="#"
<template [ngIf]="!match.isHeader() && !itemTemplate">
<button
class="dropdown-item"
(click)="selectMatch(match, $event)"
(mouseenter)="selectActive(match)"
[class.active]="isActive(match)"
[innerHtml]="hightlight(match, query)"></a>
</div>
<div *ngIf="!match.isHeader() && itemTemplate">
<a href="#"
class="dropdown-item"
(click)="selectMatch(match, $event)"
(mouseenter)="selectActive(match)"
[class.active]="isActive(match)">
[innerHtml]="hightlight(match, query)"></button>
</template>
<template [ngIf]="!match.isHeader() && itemTemplate">
<button
class="dropdown-item"
(click)="selectMatch(match, $event)"
(mouseenter)="selectActive(match)"
[class.active]="isActive(match)">
<template [ngTemplateOutlet]="itemTemplate"
[ngOutletContext]="{item: match.item, index: i}">
</template>
</a>
</div>
</button>
</template>
</template>
</div></template>
</template>
`,
// tslint:disable-next-line
host: {'class': 'dropdown open', style: 'position: absolute;' },
// tslint:disable
host: {
'class': 'dropdown open',
'[class.dropdown-menu]':'isBs4',
style: 'position: absolute;display: block;'
},
// tslint: enable
encapsulation: ViewEncapsulation.None
})
export class TypeaheadContainerComponent {
Expand Down Expand Up @@ -163,6 +166,7 @@ export class TypeaheadContainerComponent {
return itemStr;
}

@HostListener('blur')
public focusLost(): void {
this.isFocused = false;
}
Expand Down

0 comments on commit 3fb6e38

Please sign in to comment.