Skip to content

Commit

Permalink
fix: concat cached options and selected values
Browse files Browse the repository at this point in the history
  • Loading branch information
wenqi73 committed May 22, 2019
1 parent e8f9598 commit 0437cb1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
3 changes: 2 additions & 1 deletion components/select/nz-select.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ describe('SelectService', () => {
it('should updateListOfTagOption work', () => {
service.listOfCachedSelectedOption = [
{ nzValue: `option_value_0`, nzLabel: `option_label_0` },
{ nzValue: `option_value_1`, nzLabel: `option_label_1` },
{ nzValue: `option_value_miss`, nzLabel: `option_label_miss` }
// tslint:disable-next-line: no-any
] as any;
service.listOfSelectedValue = [`option_value_1`];
service.listOfTemplateOption = createListOfOption(3);
service.updateListOfTagOption();
console.log(service.listOfTagOption);
expect(service.listOfTagOption.length).toEqual(1);
expect(service.listOfTagOption[0].nzValue).toEqual('option_value_miss');
expect(service.listOfTagOption[0].nzLabel).toEqual('option_label_miss');
Expand Down
22 changes: 20 additions & 2 deletions components/select/nz-select.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,26 @@ export class NzSelectService {

updateListOfTagOption(): void {
if (this.isTagsMode) {
this.listOfTagOption = this.listOfCachedSelectedOption.filter(
comp => !this.listOfTemplateOption.find(o => this.compareWith(o.nzValue, comp.nzValue))
// 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 (
typeof componentOrValue.nzValue === 'string' &&
!this.listOfTemplateOption.find(o => this.compareWith(o.nzValue, componentOrValue.nzValue))
) {
options.push(componentOrValue);
}
return options;
},
[]
);
this.listOfTagAndTemplateOption = [...this.listOfTemplateOption.concat(this.listOfTagOption)];
} else {
Expand Down

0 comments on commit 0437cb1

Please sign in to comment.