From fea5f94be277b43569f76419d135521e1b31dfc0 Mon Sep 17 00:00:00 2001 From: simplejason Date: Thu, 28 Feb 2019 17:04:15 +0800 Subject: [PATCH] fix(module: tree-select): fix nzNodes type fix(module: tree-select): fix spec test --- components/tree-select/doc/index.en-US.md | 2 +- components/tree-select/doc/index.zh-CN.md | 2 +- components/tree-select/nz-tree-select.component.ts | 8 +++++++- components/tree-select/nz-tree-select.spec.ts | 5 +++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/components/tree-select/doc/index.en-US.md b/components/tree-select/doc/index.en-US.md index 0d14d5dd981..8520c95ba36 100755 --- a/components/tree-select/doc/index.en-US.md +++ b/components/tree-select/doc/index.en-US.md @@ -30,7 +30,7 @@ Any data whose entries are defined in a hierarchical manner is fit to use this c | `[nzShowExpand]` | Show a Expand Icon before the treeNodes | `boolean` | `true` | | `[nzShowLine]` | Shows a connecting line | `boolean` | `false` | | `[nzAsyncData]` | Load data asynchronously (should be used with NzTreeNode.addChildren(...)) | `boolean` | `false` | -| `[nzNodes]` | Data of the treeNodes | `NzTreeNode[]` | `[]` | +| `[nzNodes]` | Data of the treeNodes | `NzTreeNodeOptions[]` | `[]` | | `[nzDefaultExpandAll]` | Whether to expand all treeNodes by default | `boolean` | `false` | | `[nzDefaultExpandedKeys]` | Default expanded treeNodes | `string[]` | - | | `[nzDisplayWith]` | How to display the selected node value in the trigger | `(node: NzTreeNode) => string` | `(node: NzTreeNode) => node.title` | diff --git a/components/tree-select/doc/index.zh-CN.md b/components/tree-select/doc/index.zh-CN.md index 9492bd2a82a..dc0c3c280e4 100755 --- a/components/tree-select/doc/index.zh-CN.md +++ b/components/tree-select/doc/index.zh-CN.md @@ -30,7 +30,7 @@ title: TreeSelect | `[nzShowExpand]` | 节点前添加展开图标 | `boolean` | `true` | | `[nzShowLine]` | 是否展示连接线 | `boolean` | `false` | | `[nzAsyncData]` | 是否异步加载(显示加载状态) | `boolean` | `false` | -| `[nzNodes]` | treeNodes 数据 | `NzTreeNode[]` | `[]` | +| `[nzNodes]` | treeNodes 数据 | `NzTreeNodeOptions[]` | `[]` | | `[nzDefaultExpandAll]` | 默认展开所有树节点 | `boolean` | `false` | | `[nzDefaultExpandedKeys]` | 默认展开指定的树节点 | `string[]` | - | | `[nzDisplayWith]` | 如何在输入框显示所选的节点值的方法 | `(node: NzTreeNode) => string` | `(node: NzTreeNode) => node.title` | diff --git a/components/tree-select/nz-tree-select.component.ts b/components/tree-select/nz-tree-select.component.ts index 134299fcc58..5961a5b5581 100644 --- a/components/tree-select/nz-tree-select.component.ts +++ b/components/tree-select/nz-tree-select.component.ts @@ -340,7 +340,13 @@ export class NzTreeSelectComponent implements ControlValueAccessor, OnInit, OnDe updateSelectedNodes(init: boolean = false): void { if (init) { - const nodes = this.nzNodes.map(item => new NzTreeNode(item, null, this.nzTreeService)); + let nodes; + if (!this.nzTreeService.isArrayOfNzTreeNode(this.nzNodes)) { + // has not been new NzTreeNode + nodes = this.nzNodes.map(item => (new NzTreeNode(item, null, this.nzTreeService))); + } else { + nodes = this.nzNodes.map(item => (new NzTreeNode({ ...item.origin }, null, this.nzTreeService))); + } this.nzTreeService.initTree(nodes); if (this.nzCheckable) { this.nzTreeService.calcCheckedKeys(this.value, nodes); diff --git a/components/tree-select/nz-tree-select.spec.ts b/components/tree-select/nz-tree-select.spec.ts index 300654912c1..f47fbb17830 100644 --- a/components/tree-select/nz-tree-select.spec.ts +++ b/components/tree-select/nz-tree-select.spec.ts @@ -6,6 +6,7 @@ import { FormsModule, FormBuilder, FormGroup, ReactiveFormsModule } from '@angul import { By } from '@angular/platform-browser'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { createKeyboardEvent, dispatchFakeEvent, dispatchMouseEvent, typeInElement } from '../core/testing'; +import { NzTreeNode } from '../tree'; import { NzTreeSelectComponent } from './nz-tree-select.component'; import { NzTreeSelectModule } from './nz-tree-select.module'; @@ -222,7 +223,7 @@ describe('tree-select component', () => { tick(200); fixture.detectChanges(); expect(treeSelect.nativeElement.querySelectorAll('.ant-select-selection__choice').length).toBe(3); - const maxTagPlaceholderElement = treeSelect.nativeElement.querySelectorAll('.ant-select-selection__choice')[2] + const maxTagPlaceholderElement = treeSelect.nativeElement.querySelectorAll('.ant-select-selection__choice')[ 2 ] .querySelector('.ant-select-selection__choice__content'); expect(maxTagPlaceholderElement).toBeTruthy(); expect(maxTagPlaceholderElement.innerText.trim()).toBe(`+ ${testComponent.value.length - testComponent.maxTagCount} ...`); @@ -655,7 +656,7 @@ export class NzTestTreeSelectFormComponent { } ] } - ]; + ].map(item => new NzTreeNode(item)); constructor(private fb: FormBuilder) { this.formGroup = this.fb.group({