From 223d886cd5395630d7f8affa6c3488c90eaa897a Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 11 May 2018 11:22:55 +0800 Subject: [PATCH] fix(module: tree): fix wrong checked nodes (#1425) close #1423 --- components/tree/interface.ts | 13 ------------- components/tree/nz-tree-node.component.ts | 5 +---- components/tree/nz-tree-node.ts | 13 ++++++++++++- components/tree/nz-tree.component.ts | 2 -- components/tree/nz-tree.spec.ts | 9 +++++++++ 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/components/tree/interface.ts b/components/tree/interface.ts index 1dc4d869f6b..15ec82a6e09 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 29eea85c38d..44dc84fc651 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 0d314fbb283..830acf9a6e0 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 741a7345ec6..9e91be6db93 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 3d209606abe..3bc630f8c6f 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');