Skip to content

Commit

Permalink
fix(module:cascader): should change check state trigger ngModelChange (
Browse files Browse the repository at this point in the history
  • Loading branch information
Laffery authored Dec 17, 2024
1 parent b57ad8d commit 2c7f49a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
3 changes: 1 addition & 2 deletions components/cascader/cascader.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,6 @@ export class NzCascaderComponent
if (shouldClose) {
this.delaySetMenuVisible(false);
}
this.emitValue(this.cascaderService.values);
this.nzSelectionChange.emit(this.getAncestorOptionList(node));
this.cdr.markForCheck();
}
Expand Down Expand Up @@ -947,7 +946,7 @@ export class NzCascaderComponent
this.cascaderService.setNodeActivated(node, columnIndex, true, true);
} else {
// only update selected nodes and not set node activated by default
this.updateSelectedNodes();
this.cascaderService.setNodeSelected(node, columnIndex, true);
}
}

Expand Down
15 changes: 15 additions & 0 deletions components/cascader/cascader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1842,6 +1842,21 @@ describe('cascader', () => {
expect(leaf.classList).toContain('ant-cascader-menu-item-active');
expect(checkbox.classList).not.toContain('ant-cascader-checkbox-checked');
}));

it('should change check state trigger ngModelChange', fakeAsync(() => {
spyOn(testComponent, 'onChanges');
expect(testComponent.onChanges).not.toHaveBeenCalled();
cascader.componentInstance.setMenuVisible(true);
fixture.detectChanges();
tick(600);
fixture.detectChanges();
expect(testComponent.onChanges).not.toHaveBeenCalled();

const checkbox = getCheckboxAtColumnAndRow(1, 1)!;
checkbox.click();
fixture.detectChanges();
expect(testComponent.onChanges).toHaveBeenCalledWith([['light']]);
}));
});

describe('load data lazily', () => {
Expand Down
4 changes: 2 additions & 2 deletions components/cascader/demo/multiple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FormsModule } from '@angular/forms';
import { NzCascaderModule, NzCascaderOption } from 'ng-zorro-antd/cascader';
import { NzSafeAny } from 'ng-zorro-antd/core/types';

const options: NzCascaderOption[] = [
const getOptions = (): NzCascaderOption[] => [
{
label: 'Light',
value: 'light',
Expand Down Expand Up @@ -55,7 +55,7 @@ const options: NzCascaderOption[] = [
`
})
export class NzDemoCascaderMultipleComponent {
nzOptions: NzCascaderOption[] = options;
nzOptions: NzCascaderOption[] = getOptions();
values: NzSafeAny[][] | null = null;

onChanges(values: NzSafeAny[][]): void {
Expand Down

0 comments on commit 2c7f49a

Please sign in to comment.