Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Update search change to occur on ngModel change, not angular change #960

Merged
merged 2 commits into from
Aug 1, 2017
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 2 deletions src/modules/search/search.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
<input
type="text"
class="sky-form-control sky-search-input"
[(ngModel)]="searchText"
(change)="searchTextChanged(searchText)"
[ngModel]="searchText"
(ngModelChange)="searchTextChanged($event)"
(keyup)="enterPress($event, searchText)"
(focus)="inputFocused(true)"
(blur)="inputFocused(false)"
Expand Down
20 changes: 18 additions & 2 deletions src/modules/search/search.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ describe('Search component', () => {
fixture.detectChanges();
}

function setNgModel(text: string) {
let inputEvent = document.createEvent('Event');
let params = {
bubbles: false,
cancelable: false
};
inputEvent.initEvent('input', params.bubbles, params.cancelable);

let inputEl = element.query(By.css('input'));
inputEl.nativeElement.value = text;

inputEl.nativeElement.dispatchEvent(inputEvent);
fixture.detectChanges();
}

function triggerInputEnter() {
let inputEl = element.query(By.css('input'));
inputEl.triggerEventHandler('keyup', { which: 13});
Expand Down Expand Up @@ -223,8 +238,8 @@ describe('Search component', () => {
expect(component.lastSearchTextApplied).toBe('applied text');
});

it('should emit search change event on input change', () => {
setInput('change text');
it('should emit search change event on ngModel change', () => {
setNgModel('change text');
expect(component.lastSearchTextChanged).toBe('change text');
expect(component.lastSearchTextApplied).not.toBe('change text');
});
Expand Down Expand Up @@ -258,6 +273,7 @@ describe('Search component', () => {

expect(element.query(By.css('.sky-input-group-clear')).nativeElement).not.toBeVisible();
expect(component.lastSearchTextApplied).toBe('');
expect(component.lastSearchTextChanged).toBe('');
});

it('should apply the correct focus class', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/modules/search/search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export class SkySearchComponent implements OnDestroy, OnInit, OnChanges {
this.clearButtonShown = false;

this.searchAdapter.focusInput(this.elRef);
this.searchChange.emit(this.searchText);

this.searchApply.emit(this.searchText);
}
Expand All @@ -185,6 +186,7 @@ export class SkySearchComponent implements OnDestroy, OnInit, OnChanges {
}

public searchTextChanged(searchText: string) {
this.searchText = searchText;
this.searchChange.emit(searchText);
}

Expand Down