Skip to content

Commit

Permalink
fix(module:tree-select): default tags incorrect in strictly mode (#4368)
Browse files Browse the repository at this point in the history
close #4364
  • Loading branch information
hsuanxyz authored Nov 7, 2019
1 parent 475bbc4 commit a6547a0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
4 changes: 3 additions & 1 deletion components/tree-select/nz-tree-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())];
}

Expand Down
26 changes: 25 additions & 1 deletion components/tree-select/nz-tree-select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
dispatchMouseEvent,
typeInElement,
MockNgZone,
NzTreeNode, NzTreeNodeOptions
NzTreeNode,
NzTreeNodeOptions
} from 'ng-zorro-antd/core';

import { NzTreeSelectComponent } from './nz-tree-select.component';
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -620,6 +642,7 @@ export class NzTestTreeSelectBasicComponent {
[nzNodes]="nodes"
[nzShowSearch]="showSearch"
[nzCheckable]="true"
[nzCheckStrictly]="checkStrictly"
[(ngModel)]="value"
>
</nz-tree-select>
Expand All @@ -630,6 +653,7 @@ export class NzTestTreeSelectCheckableComponent {
expandKeys = ['1001', '10001'];
value: string[] | null = ['1000122'];
showSearch = false;
checkStrictly = false;
nodes = [
{
title: 'root1',
Expand Down
17 changes: 3 additions & 14 deletions components/tree/nz-tree.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { takeUntil } from 'rxjs/operators';

import {
isNotNil,
toBoolean,
warnDeprecation,
InputBoolean,
NzConfigService,
Expand Down Expand Up @@ -114,16 +113,7 @@ export class NzTreeComponent extends NzTreeBase implements OnInit, OnDestroy, Co

@Input() nzBeforeDrop: (confirm: NzFormatBeforeDropEvent) => Observable<boolean>;

@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
Expand Down Expand Up @@ -223,7 +213,6 @@ export class NzTreeComponent extends NzTreeBase implements OnInit, OnDestroy, Co
@Output() readonly nzOnDragEnd = new EventEmitter<NzFormatEmitEvent>();

_searchValue: string;
_nzMultiple: boolean = false;
nzDefaultSubject = new ReplaySubject<{ type: string; keys: string[] }>(6);
destroy$ = new Subject();
prefixCls = 'ant-tree';
Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit a6547a0

Please sign in to comment.