diff --git a/components/tree/interface.ts b/components/tree/interface.ts index 1dc4d869f6..15ec82a6e0 100644 --- a/components/tree/interface.ts +++ b/components/tree/interface.ts @@ -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[]; -} diff --git a/components/tree/nz-tree-node.component.ts b/components/tree/nz-tree-node.component.ts index 29eea85c38..44dc84fc65 100644 --- a/components/tree/nz-tree-node.component.ts +++ b/components/tree/nz-tree-node.component.ts @@ -92,7 +92,6 @@ import { NzTreeService } from './nz-tree.service'; [nzBeforeDrop]="nzBeforeDrop" [nzCheckStrictly]="nzCheckStrictly" [nzDefaultExpandAll]="nzDefaultExpandAll" - [nzDefaultCheckedKeys]="nzDefaultCheckedKeys" [nzDefaultExpandedKeys]="nzDefaultExpandedKeys" [nzDefaultSelectedKeys]="nzDefaultSelectedKeys" [nzTreeTemplate]="nzTreeTemplate" @@ -132,7 +131,6 @@ export class NzTreeNodeComponent implements OnInit, AfterViewInit { dragPos = 2; prefixCls = 'ant-tree'; _treeNode; - _checkStrictly; _expandAll = false; _defaultCheckedKeys = []; _defaultExpandedKeys = []; @@ -155,7 +153,6 @@ export class NzTreeNodeComponent implements OnInit, AfterViewInit { @Input() nzCheckable: boolean; @Input() nzAsyncData; @Input() nzCheckStrictly: boolean; - @Input() nzDefaultCheckedKeys: string[]; @Input() nzTreeTemplate: TemplateRef; @Input() nzBeforeDrop: (confirm: NzFormatBeforeDropEvent) => Observable; @@ -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)); } diff --git a/components/tree/nz-tree-node.ts b/components/tree/nz-tree-node.ts index 0d314fbb28..830acf9a6e 100644 --- a/components/tree/nz-tree-node.ts +++ b/components/tree/nz-tree-node.ts @@ -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; diff --git a/components/tree/nz-tree.component.ts b/components/tree/nz-tree.component.ts index 741a7345ec..9e91be6db9 100644 --- a/components/tree/nz-tree.component.ts +++ b/components/tree/nz-tree.component.ts @@ -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)" @@ -52,7 +51,6 @@ import { NzTreeService } from './nz-tree.service'; ] }) export class NzTreeComponent implements OnInit { - _root: NzTreeNode[] = []; _searchValue; _showLine = false; _prefixCls = 'ant-tree'; diff --git a/components/tree/nz-tree.spec.ts b/components/tree/nz-tree.spec.ts index 3d209606ab..3bc630f8c6 100644 --- a/components/tree/nz-tree.spec.ts +++ b/components/tree/nz-tree.spec.ts @@ -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');