Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(module: tree): fix wrong checked nodes #1425

Merged
merged 1 commit into from
May 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions components/tree/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,3 @@ export interface NzFormatBeforeDropEvent {
node: NzTreeNode;
pos: number;
}

export interface NzTreeNodeOptions {
title: string;
key: string;
isLeaf?: boolean;
checked?: boolean;
selected?: boolean;
selectable?: boolean;
disabled?: boolean;
disableCheckbox?: boolean;
expanded?: boolean;
children?: NzTreeNodeOptions[];
}
5 changes: 1 addition & 4 deletions components/tree/nz-tree-node.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ import { NzTreeService } from './nz-tree.service';
[nzBeforeDrop]="nzBeforeDrop"
[nzCheckStrictly]="nzCheckStrictly"
[nzDefaultExpandAll]="nzDefaultExpandAll"
[nzDefaultCheckedKeys]="nzDefaultCheckedKeys"
[nzDefaultExpandedKeys]="nzDefaultExpandedKeys"
[nzDefaultSelectedKeys]="nzDefaultSelectedKeys"
[nzTreeTemplate]="nzTreeTemplate"
Expand Down Expand Up @@ -132,7 +131,6 @@ export class NzTreeNodeComponent implements OnInit, AfterViewInit {
dragPos = 2;
prefixCls = 'ant-tree';
_treeNode;
_checkStrictly;
_expandAll = false;
_defaultCheckedKeys = [];
_defaultExpandedKeys = [];
Expand All @@ -155,7 +153,6 @@ export class NzTreeNodeComponent implements OnInit, AfterViewInit {
@Input() nzCheckable: boolean;
@Input() nzAsyncData;
@Input() nzCheckStrictly: boolean;
@Input() nzDefaultCheckedKeys: string[];
@Input() nzTreeTemplate: TemplateRef<void>;
@Input() nzBeforeDrop: (confirm: NzFormatBeforeDropEvent) => Observable<boolean>;

Expand Down Expand Up @@ -389,8 +386,8 @@ export class NzTreeNodeComponent implements OnInit, AfterViewInit {
node.isHalfChecked = false;
this.nzTreeService.setCheckedNodeListStrict(this.nzTreeNode);
} else {
this.nzTreeService.setCheckedNodeList(this.nzTreeNode);
this.nzTreeService.checkTreeNode(node);
this.nzTreeService.setCheckedNodeList(this.nzTreeNode);
}
this.clickCheckBox.emit(this.nzTreeService.formatEvent('check', node, $event));
}
Expand Down
13 changes: 12 additions & 1 deletion components/tree/nz-tree-node.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import { NzTreeNodeOptions } from './interface';
export interface NzTreeNodeOptions {
title: string;
key: string;
isLeaf?: boolean;
checked?: boolean;
selected?: boolean;
selectable?: boolean;
disabled?: boolean;
disableCheckbox?: boolean;
expanded?: boolean;
children?: NzTreeNodeOptions[];
}

export class NzTreeNode {
title?: string;
Expand Down
2 changes: 0 additions & 2 deletions components/tree/nz-tree.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { NzTreeService } from './nz-tree.service';
[nzBeforeDrop]="nzBeforeDrop"
[nzCheckStrictly]="nzCheckStrictly"
[nzDefaultExpandAll]="nzDefaultExpandAll"
[nzDefaultCheckedKeys]="nzDefaultCheckedKeys"
[nzDefaultExpandedKeys]="nzDefaultExpandedKeys"
[nzDefaultSelectedKeys]="nzDefaultSelectedKeys"
(clickCheckBox)="nzCheckBoxChange.emit($event)"
Expand All @@ -52,7 +51,6 @@ import { NzTreeService } from './nz-tree.service';
]
})
export class NzTreeComponent implements OnInit {
_root: NzTreeNode[] = [];
_searchValue;
_showLine = false;
_prefixCls = 'ant-tree';
Expand Down
9 changes: 9 additions & 0 deletions components/tree/nz-tree.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ describe('tree component test', () => {
expect(treeElement.querySelectorAll('.ant-tree-checkbox-checked').length).toEqual(6);
expect(checkSpy).toHaveBeenCalled();
expect(checkSpy).toHaveBeenCalledTimes(1);
// for bug test https://github.com/NG-ZORRO/ng-zorro-antd/issues/1423
// auto merge child node
expect(treeInstance.treeComponent.getCheckedNodeList().length).toEqual(1);
expect(treeInstance.treeComponent.getCheckedNodeList()[0].title).toEqual('root1');
// cancel checked status
dispatchMouseEvent(targetNode, 'click');
fixture.detectChanges();
expect(treeElement.querySelectorAll('.ant-tree-checkbox-checked').length).toEqual(0);
expect(treeInstance.treeComponent.getCheckedNodeList().length).toEqual(0);
// click toggle checked
dispatchMouseEvent(targetNode, 'click');
dispatchMouseEvent(targetNode, 'click');
Expand Down