Skip to content

Commit

Permalink
fix(module:cascader): restore its value after cancel search (#6088)
Browse files Browse the repository at this point in the history
  • Loading branch information
stygian-desolator authored Nov 30, 2020
1 parent 123982f commit 22ddc60
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions components/cascader/cascader.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ export class NzCascaderComponent implements NzCascaderComponentAsSource, OnInit,
this.scrollToActivatedOptions();
}

if (!visible) {
this.inputValue = '';
}

this.menuVisible = visible;
this.nzVisibleChange.emit(visible);
this.cdr.detectChanges();
Expand Down
18 changes: 18 additions & 0 deletions components/cascader/cascader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,24 @@ describe('cascader', () => {
expect(itemEl1.innerText).toBe('Zhejiang');
}));

it('should clear input value when searching cancel', fakeAsync(() => {
testComponent.values = ['zhengjiang', 'hangzhou', 'xihu'];
testComponent.nzShowSearch = true;
fixture.detectChanges();
cascader.nativeElement.click();
testComponent.cascader.inputValue = 'o';
fixture.detectChanges();
flush();
fixture.detectChanges();
expect(testComponent.cascader.menuVisible).toBe(true);
dispatchKeyboardEvent(cascader.nativeElement, 'keydown', ESCAPE);
fixture.detectChanges();
flush();
fixture.detectChanges();
expect(testComponent.cascader.inputValue).toBe('');
expect(testComponent.values).toEqual(['zhengjiang', 'hangzhou', 'xihu']);
}));

it('should support nzLabelProperty', fakeAsync(() => {
testComponent.nzShowSearch = true;
testComponent.nzLabelProperty = 'l';
Expand Down

0 comments on commit 22ddc60

Please sign in to comment.