diff --git a/components/tree-select/nz-tree-select.component.ts b/components/tree-select/nz-tree-select.component.ts index b739b0dae70..f477786b662 100644 --- a/components/tree-select/nz-tree-select.component.ts +++ b/components/tree-select/nz-tree-select.component.ts @@ -396,13 +396,15 @@ export class NzTreeSelectComponent extends NzTreeBase implements ControlValueAcc if (init) { const nodes = this.coerceTreeNodes(this.nzNodes); this.nzTreeService.isMultiple = this.isMultiple; + this.nzTreeService.isCheckStrictly = this.nzCheckStrictly; this.nzTreeService.initTree(nodes); if (this.nzCheckable) { - this.nzTreeService.calcCheckedKeys(this.value, nodes); + this.nzTreeService.calcCheckedKeys(this.value, nodes, this.nzCheckStrictly); } else { this.nzTreeService.calcSelectedKeys(this.value, nodes, this.isMultiple); } } + this.selectedNodes = [...(this.nzCheckable ? this.getCheckedNodeList() : this.getSelectedNodeList())]; } diff --git a/components/tree-select/nz-tree-select.spec.ts b/components/tree-select/nz-tree-select.spec.ts index 333763cda2d..86adb65a6e6 100644 --- a/components/tree-select/nz-tree-select.spec.ts +++ b/components/tree-select/nz-tree-select.spec.ts @@ -12,7 +12,8 @@ import { dispatchMouseEvent, typeInElement, MockNgZone, - NzTreeNode, NzTreeNodeOptions + NzTreeNode, + NzTreeNodeOptions } from 'ng-zorro-antd/core'; import { NzTreeSelectComponent } from './nz-tree-select.component'; @@ -345,6 +346,27 @@ describe('tree-select component', () => { expect(testComponent.nzSelectTreeComponent.value.length).toBe(0); })); + it('should not check strictly work', fakeAsync(() => { + fixture.detectChanges(); + testComponent.value = ['1001', '10001', '100012']; + fixture.detectChanges(); + tick(); + fixture.detectChanges(); + expect(testComponent.nzSelectTreeComponent.selectedNodes.length).toBe(1); + })); + + it('should check strictly work', fakeAsync(() => { + fixture.detectChanges(); + testComponent.checkStrictly = true; + testComponent.value = ['1001', '10001', '100012']; + fixture.detectChanges(); + tick(); + fixture.detectChanges(); + expect(testComponent.nzSelectTreeComponent.selectedNodes.length).toBe(3); + testComponent.checkStrictly = false; + fixture.detectChanges(); + })); + it('should remove checked when press backs', fakeAsync(() => { treeSelect.nativeElement.click(); fixture.detectChanges(); @@ -620,6 +642,7 @@ export class NzTestTreeSelectBasicComponent { [nzNodes]="nodes" [nzShowSearch]="showSearch" [nzCheckable]="true" + [nzCheckStrictly]="checkStrictly" [(ngModel)]="value" > @@ -630,6 +653,7 @@ export class NzTestTreeSelectCheckableComponent { expandKeys = ['1001', '10001']; value: string[] | null = ['1000122']; showSearch = false; + checkStrictly = false; nodes = [ { title: 'root1', diff --git a/components/tree/nz-tree.component.ts b/components/tree/nz-tree.component.ts index 91277e9cca7..28914ae6eed 100644 --- a/components/tree/nz-tree.component.ts +++ b/components/tree/nz-tree.component.ts @@ -30,7 +30,6 @@ import { takeUntil } from 'rxjs/operators'; import { isNotNil, - toBoolean, warnDeprecation, InputBoolean, NzConfigService, @@ -114,16 +113,7 @@ export class NzTreeComponent extends NzTreeBase implements OnInit, OnDestroy, Co @Input() nzBeforeDrop: (confirm: NzFormatBeforeDropEvent) => Observable; - @Input() - @InputBoolean() - set nzMultiple(value: boolean) { - this._nzMultiple = toBoolean(value); - this.nzTreeService.isMultiple = toBoolean(value); - } - - get nzMultiple(): boolean { - return this._nzMultiple; - } + @Input() @InputBoolean() nzMultiple = false; @Input() // tslint:disable-next-line:no-any @@ -223,7 +213,6 @@ export class NzTreeComponent extends NzTreeBase implements OnInit, OnDestroy, Co @Output() readonly nzOnDragEnd = new EventEmitter(); _searchValue: string; - _nzMultiple: boolean = false; nzDefaultSubject = new ReplaySubject<{ type: string; keys: string[] }>(6); destroy$ = new Subject(); prefixCls = 'ant-tree'; @@ -340,10 +329,10 @@ export class NzTreeComponent extends NzTreeBase implements OnInit, OnDestroy, Co ngOnChanges(changes: { [propertyName: string]: SimpleChange }): void { if (changes.nzCheckStrictly) { - this.nzTreeService.isCheckStrictly = toBoolean(changes.nzCheckStrictly.currentValue); + this.nzTreeService.isCheckStrictly = this.nzCheckStrictly; } if (changes.nzMultiple) { - this.nzTreeService.isMultiple = toBoolean(changes.nzMultiple.currentValue); + this.nzTreeService.isMultiple = this.nzMultiple; } }