Skip to content

Commit

Permalink
fix(module:select): wrong sort in group option (#5063)
Browse files Browse the repository at this point in the history
  • Loading branch information
wenqi73 authored Apr 17, 2020
1 parent 2c4c537 commit af39d5f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/select/select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
26 changes: 26 additions & 0 deletions components/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestSelectMultipleComponent>;
Expand Down

0 comments on commit af39d5f

Please sign in to comment.