Skip to content

Commit

Permalink
fix(module: tree): fix wrong checked nodes (#1425)
Browse files Browse the repository at this point in the history
close #1423
  • Loading branch information
Jason authored and vthinkxie committed May 11, 2018
1 parent 35da659 commit 5a06694
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
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

0 comments on commit 5a06694

Please sign in to comment.