Skip to content

Commit 2c7f49a

Browse files
authored
fix(module:cascader): should change check state trigger ngModelChange (#8941)
1 parent b57ad8d commit 2c7f49a

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

components/cascader/cascader.component.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,6 @@ export class NzCascaderComponent
535535
if (shouldClose) {
536536
this.delaySetMenuVisible(false);
537537
}
538-
this.emitValue(this.cascaderService.values);
539538
this.nzSelectionChange.emit(this.getAncestorOptionList(node));
540539
this.cdr.markForCheck();
541540
}
@@ -947,7 +946,7 @@ export class NzCascaderComponent
947946
this.cascaderService.setNodeActivated(node, columnIndex, true, true);
948947
} else {
949948
// only update selected nodes and not set node activated by default
950-
this.updateSelectedNodes();
949+
this.cascaderService.setNodeSelected(node, columnIndex, true);
951950
}
952951
}
953952

components/cascader/cascader.spec.ts

+15
Original file line numberDiff line numberDiff line change
@@ -1842,6 +1842,21 @@ describe('cascader', () => {
18421842
expect(leaf.classList).toContain('ant-cascader-menu-item-active');
18431843
expect(checkbox.classList).not.toContain('ant-cascader-checkbox-checked');
18441844
}));
1845+
1846+
it('should change check state trigger ngModelChange', fakeAsync(() => {
1847+
spyOn(testComponent, 'onChanges');
1848+
expect(testComponent.onChanges).not.toHaveBeenCalled();
1849+
cascader.componentInstance.setMenuVisible(true);
1850+
fixture.detectChanges();
1851+
tick(600);
1852+
fixture.detectChanges();
1853+
expect(testComponent.onChanges).not.toHaveBeenCalled();
1854+
1855+
const checkbox = getCheckboxAtColumnAndRow(1, 1)!;
1856+
checkbox.click();
1857+
fixture.detectChanges();
1858+
expect(testComponent.onChanges).toHaveBeenCalledWith([['light']]);
1859+
}));
18451860
});
18461861

18471862
describe('load data lazily', () => {

components/cascader/demo/multiple.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { FormsModule } from '@angular/forms';
44
import { NzCascaderModule, NzCascaderOption } from 'ng-zorro-antd/cascader';
55
import { NzSafeAny } from 'ng-zorro-antd/core/types';
66

7-
const options: NzCascaderOption[] = [
7+
const getOptions = (): NzCascaderOption[] => [
88
{
99
label: 'Light',
1010
value: 'light',
@@ -55,7 +55,7 @@ const options: NzCascaderOption[] = [
5555
`
5656
})
5757
export class NzDemoCascaderMultipleComponent {
58-
nzOptions: NzCascaderOption[] = options;
58+
nzOptions: NzCascaderOption[] = getOptions();
5959
values: NzSafeAny[][] | null = null;
6060

6161
onChanges(values: NzSafeAny[][]): void {

0 commit comments

Comments
 (0)