Skip to content

Commit

Permalink
fix(module:select): display error when in tag and search mode (#3442)
Browse files Browse the repository at this point in the history
close #3424
* fix(module:select): display error when in tag and search mode

* fix: concat cached options and selected values
  • Loading branch information
wenqi73 authored and simplejason committed Jun 5, 2019
1 parent 4329b51 commit a05f5a5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
13 changes: 11 additions & 2 deletions components/select/nz-select.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,19 @@ describe('SelectService', () => {
service.mode = 'tags';
});
it('should updateListOfTagOption work', () => {
service.listOfSelectedValue = [`option_value_0`, `option_value_1`, `option_value_miss`];
service.listOfCachedSelectedOption = [
{ nzValue: `option_value_0`, nzLabel: `option_label_0` },
{ nzValue: `option_value_miss`, nzLabel: `option_label_miss` }
// tslint:disable-next-line: no-any
] as any;
service.listOfSelectedValue = [`option_value_1`, `option_value_miss_1`];
service.listOfTemplateOption = createListOfOption(3);
service.updateListOfTagOption();
expect(service.listOfTagOption.length).toEqual(1);
expect(service.listOfTagOption.length).toEqual(2);
expect(service.listOfTagOption[0].nzValue).toEqual('option_value_miss');
expect(service.listOfTagOption[0].nzLabel).toEqual('option_label_miss');
expect(service.listOfTagOption[1].nzValue).toEqual('option_value_miss_1');
expect(service.listOfTagOption[1].nzLabel).toEqual('option_value_miss_1');
});
it('should updateAddTagOption work', () => {
service.listOfSelectedValue = [`option_value_0`, `option_value_1`];
Expand Down
28 changes: 20 additions & 8 deletions components/select/nz-select.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,27 @@ export class NzSelectService {

updateListOfTagOption(): void {
if (this.isTagsMode) {
const listOfMissValue = this.listOfSelectedValue.filter(
value => !this.listOfTemplateOption.find(o => this.compareWith(o.nzValue, value))
// https://github.com/NG-ZORRO/ng-zorro-antd/issues/3424
this.listOfTagOption = [...this.listOfCachedSelectedOption, ...this.listOfSelectedValue].reduce(
(options: NzOptionComponent[], componentOrValue) => {
if (
typeof componentOrValue === 'string' &&
!this.listOfTemplateOption.find(o => this.compareWith(o.nzValue, componentOrValue))
) {
const nzOptionComponent = new NzOptionComponent();
nzOptionComponent.nzValue = componentOrValue;
nzOptionComponent.nzLabel = componentOrValue;
options.push(nzOptionComponent);
} else if (
componentOrValue.nzValue &&
!this.listOfTemplateOption.find(o => this.compareWith(o.nzValue, componentOrValue.nzValue))
) {
options.push(componentOrValue);
}
return options;
},
[]
);
this.listOfTagOption = listOfMissValue.map(value => {
const nzOptionComponent = new NzOptionComponent();
nzOptionComponent.nzValue = value;
nzOptionComponent.nzLabel = value;
return nzOptionComponent;
});
this.listOfTagAndTemplateOption = [...this.listOfTemplateOption.concat(this.listOfTagOption)];
} else {
this.listOfTagAndTemplateOption = [...this.listOfTemplateOption];
Expand Down

0 comments on commit a05f5a5

Please sign in to comment.