Skip to content

Commit

Permalink
fix(module:select): remove duplicate drop-down menu options when nzMo…
Browse files Browse the repository at this point in the history
…de === 'tags' (NG-ZORRO#3559)

close NG-ZORRO#3559

* fix(module:select): remove duplicate drop-down menu options when nzMode === 'tags'(NG-ZORRO#3559)
  • Loading branch information
lzdw committed Jun 14, 2019
1 parent e59171b commit 7475a74
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
13 changes: 8 additions & 5 deletions components/select/nz-select.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,20 @@ describe('SelectService', () => {
it('should updateListOfTagOption work', () => {
service.listOfCachedSelectedOption = [
{ nzValue: `option_value_0`, nzLabel: `option_label_0` },
{ nzValue: `option_value_miss`, nzLabel: `option_label_miss` }
{ nzValue: `option_value_miss`, nzLabel: `option_label_miss` },
{ nzValue: `option_value_a`, nzLabel: `option_label_a` }
// tslint:disable-next-line: no-any
] as any;
service.listOfSelectedValue = [`option_value_1`, `option_value_miss_1`];
service.listOfSelectedValue = [`option_value_1`, `option_value_miss_1`, `option_value_a`];
service.listOfTemplateOption = createListOfOption(3);
service.updateListOfTagOption();
expect(service.listOfTagOption.length).toEqual(2);
expect(service.listOfTagOption.length).toEqual(3);
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');
expect(service.listOfTagOption[1].nzValue).toEqual('option_value_a');
expect(service.listOfTagOption[1].nzLabel).toEqual('option_label_a');
expect(service.listOfTagOption[2].nzValue).toEqual('option_value_miss_1');
expect(service.listOfTagOption[2].nzLabel).toEqual('option_value_miss_1');
});
it('should updateAddTagOption work', () => {
service.listOfSelectedValue = [`option_value_0`, `option_value_1`];
Expand Down
5 changes: 3 additions & 2 deletions components/select/nz-select.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,18 @@ export class NzSelectService {
// https://github.com/NG-ZORRO/ng-zorro-antd/issues/3424
this.listOfTagOption = [...this.listOfCachedSelectedOption, ...this.listOfSelectedValue].reduce(
(options: NzOptionComponent[], componentOrValue) => {
// https://github.com/NG-ZORRO/ng-zorro-antd/issues/3559
if (
typeof componentOrValue === 'string' &&
!this.listOfTemplateOption.find(o => this.compareWith(o.nzValue, componentOrValue))
![...this.listOfTemplateOption, ...options].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))
![...this.listOfTemplateOption, ...options].find(o => this.compareWith(o.nzValue, componentOrValue.nzValue))
) {
options.push(componentOrValue);
}
Expand Down

0 comments on commit 7475a74

Please sign in to comment.