Skip to content

Commit

Permalink
Merge dfa3e98 into 8368efa
Browse files Browse the repository at this point in the history
  • Loading branch information
varnastadeus committed Sep 5, 2018
2 parents 8368efa + dfa3e98 commit 7eb0e5e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -159,6 +159,7 @@ map: {
| (close) | Fired on select dropdown close |
| (clear) | Fired on clear icon click |
| (focus) | Fired on select focus |
| (search) | Fired while typing search term |
| (open) | Fired on select dropdown open |
| (remove) | Fired when item is removed |
| (scroll) | Fired when scrolled. Provides the start and end index of the currently available items. Can be used for loading more items in chunks before the user has scrolled all the way to the bottom of the list. |
Expand Down
25 changes: 15 additions & 10 deletions demo/app/examples/events.component.ts
@@ -1,4 +1,4 @@
import { Component, ChangeDetectionStrategy } from '@angular/core';
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { DataService } from '../shared/data.service';


Expand All @@ -21,6 +21,7 @@ interface AngSelectEvent {
(open)="onOpen()"
(close)="onClose()"
(focus)="onFocus($event)"
(search)="onSearch($event)"
(blur)="onBlur($event)"
(clear)="onClear()"
(add)="onAdd($event)"
Expand Down Expand Up @@ -57,39 +58,43 @@ export class SelectEventsComponent {
}

onChange($event) {
this.events.push({name: '(change)', value: $event});
this.events.push({ name: '(change)', value: $event });
}

onFocus($event: Event) {
this.events.push({name: '(focus)', value: $event});
this.events.push({ name: '(focus)', value: $event });
}

onBlur($event: Event) {
this.events.push({name: '(blur)', value: $event});
this.events.push({ name: '(blur)', value: $event });
}

onOpen() {
this.events.push({name: '(open)', value: null});
this.events.push({ name: '(open)', value: null });
}

onClose() {
this.events.push({name: '(close)', value: null});
this.events.push({ name: '(close)', value: null });
}

onAdd($event) {
this.events.push({name: '(add)', value: $event});
this.events.push({ name: '(add)', value: $event });
}

onRemove($event) {
this.events.push({name: '(remove)', value: $event});
this.events.push({ name: '(remove)', value: $event });
}

onClear() {
this.events.push({name: '(clear)', value: null});
this.events.push({ name: '(clear)', value: null });
}

onScrollToEnd($event) {
this.events.push({name: '(scrollToEnd)', value: $event});
this.events.push({ name: '(scrollToEnd)', value: $event });
}

onSearch($event) {
this.events.push({ name: '(search)', value: $event })
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/ng-select/ng-select.component.spec.ts
Expand Up @@ -2442,6 +2442,23 @@ describe('NgSelectComponent', function () {
expect(fixture.componentInstance.onOpen).toHaveBeenCalledTimes(1);
}));

it('should fire search event', fakeAsync(() => {
const fixture = createTestingModule(
NgSelectTestCmp,
`<ng-select [items]="cities"
(search)="onSearch($event)"
[(ngModel)]="selectedCity">
</ng-select>`);

spyOn(fixture.componentInstance, 'onSearch');

fixture.componentInstance.select.filter('term');
tickAndDetectChanges(fixture);

expect(fixture.componentInstance.onSearch).toHaveBeenCalledTimes(1);
expect(fixture.componentInstance.onSearch).toHaveBeenCalledWith('term');
}));

it('should fire close event once', fakeAsync(() => {
const fixture = createTestingModule(
NgSelectTestCmp,
Expand Down Expand Up @@ -3035,6 +3052,7 @@ class NgSelectTestCmp {
onAdd() { }
onRemove() { }
onClear() { }
onSearch() { }
onScroll() { }
onScrollToEnd() { }
}
Expand Down
2 changes: 2 additions & 0 deletions src/ng-select/ng-select.component.ts
Expand Up @@ -469,6 +469,8 @@ export class NgSelectComponent implements OnDestroy, OnChanges, AfterViewInit, C
this.itemsList.markSelectedOrDefault(this.markFirst);
}
}

this.searchEvent.emit(term);
}

onInputFocus($event) {
Expand Down

0 comments on commit 7eb0e5e

Please sign in to comment.