Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- added typeaheadOnBlur event #1639

Merged
merged 5 commits into from
Feb 28, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions demo/src/ng-api-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2095,6 +2095,10 @@ export const ngdoc: any = {
{
"name": "typeaheadOnSelect",
"description": "<p>fired when option was selected, return object with data of this option </p>\n"
},
{
"name": "typeaheadOnBlur",
"description": "<p>fired when blur event occurres. returns the active item </p>\n"
}
],
"properties": [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@angular/router": "^3.4.4",
"@angular/tsc-wrapped": "0.5.1",
"@ngtools/webpack": "1.2.7",
"@types/jasmine": "^2.5.41",
"@types/jasmine": "2.5.41",
"@types/marked": "0.0.28",
"@types/node": "7.0.0",
"@types/webpack": "^2.2.2",
Expand Down
4 changes: 4 additions & 0 deletions src/typeahead/typeahead-container.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export class TypeaheadContainerComponent {
this.element = element;
}

public get active(): TypeaheadMatch {
return this._active;
}

public get matches(): TypeaheadMatch[] {
return this._matches;
}
Expand Down
10 changes: 3 additions & 7 deletions src/typeahead/typeahead.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export class TypeaheadDirective implements OnInit, OnDestroy {
@Output() public typeaheadNoResults: EventEmitter<boolean> = new EventEmitter();
/** fired when option was selected, return object with data of this option */
@Output() public typeaheadOnSelect: EventEmitter<TypeaheadMatch> = new EventEmitter();
/** fired when blur event occurres. returns the active item */
@Output() public typeaheadOnBlur: EventEmitter<any> = new EventEmitter();

/**
* A selector specifying the element the typeahead should be appended to.
Expand Down Expand Up @@ -143,6 +145,7 @@ export class TypeaheadDirective implements OnInit, OnDestroy {
@HostListener('blur')
public onBlur(): void {
if (this._container && !this._container.isFocused) {
this.typeaheadOnBlur.emit(this._container.active);
this.hide();
}
}
Expand All @@ -159,13 +162,6 @@ export class TypeaheadDirective implements OnInit, OnDestroy {
e.preventDefault();
return;
}

// if tab default browser behavior will select next input field, and
// therefore we should close the items list
if (e.keyCode === 9) {
this.hide();
return;
}
}

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.


public constructor(control: NgControl, viewContainerRef: ViewContainerRef, element: ElementRef, renderer: Renderer, cis: ComponentLoaderFactory) {
Expand Down