diff --git a/components/select/select.component.ts b/components/select/select.component.ts index d5a5302ccd9..86f57b977a1 100644 --- a/components/select/select.component.ts +++ b/components/select/select.component.ts @@ -293,7 +293,7 @@ export class NzSelectComponent implements ControlValueAccessor, OnInit, AfterVie if (this.listOfNzOptionGroupComponent) { this.listOfNzOptionGroupComponent.forEach(o => { const groupItem = { groupLabel: o.nzLabel, type: 'group', key: o.nzLabel } as NzSelectItemInterface; - const index = this.listOfContainerItem.findIndex(item => groupItem.groupLabel === item.groupLabel); + const index = listOfContainerItem.findIndex(item => groupItem.groupLabel === item.groupLabel); listOfContainerItem.splice(index, 0, groupItem); }); } diff --git a/components/select/select.spec.ts b/components/select/select.spec.ts index c35531652a4..48281111692 100644 --- a/components/select/select.spec.ts +++ b/components/select/select.spec.ts @@ -335,6 +335,32 @@ describe('select', () => { expect(document.querySelectorAll('nz-option-item-group')[0]!.textContent).toBe('change-group'); expect(document.querySelectorAll('nz-option-item')[0].textContent).toBe('change-label'); })); + + it('should group item sort be right', fakeAsync(() => { + component.listOfGroup = [ + { + nzLabel: 'group-1', + children: [ + { nzValue: 'value_01', nzLabel: 'label_01' }, + { nzValue: 'value_02', nzLabel: 'label_02' } + ] + }, + { + nzLabel: 'group-2', + children: [ + { nzValue: 'value_03', nzLabel: 'label_03' }, + { nzValue: 'value_04', nzLabel: 'label_04' } + ] + } + ]; + component.nzOpen = true; + fixture.detectChanges(); + flush(); + fixture.detectChanges(); + expect( + document.querySelectorAll('nz-option-item')[0].parentElement!.nextElementSibling!.querySelector('nz-option-item')!.textContent + ).toBe('label_02'); + })); }); describe('multiple mode', () => { let testBed: ComponentBed;