Skip to content

Commit

Permalink
[WIP] fix(module: tree): fix nzOnSearchChange & folder tree demo
Browse files Browse the repository at this point in the history
  • Loading branch information
simplejason committed Jun 4, 2018
1 parent e76b2fa commit b17647f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
36 changes: 26 additions & 10 deletions components/tree/demo/dir-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import { NzFormatEmitEvent, NzTreeNode } from 'ng-zorro-antd';
[nzShowExpand]="true"
[nzDraggable]="true"
(nzOnDragStart)="dragStart($event)"
(nzClick)="activeNode($event)">
(nzClick)="activeNode($event)"
(nzDblClick)="openFolder($event)"
>
<ng-template #nzTreeTemplate let-node>
<span class="custom-node" draggable="true" aria-grabbed="true" [class.active]="activedNode?.key===node.key">
<span *ngIf="!node.isLeaf" [class.shine-animate]="node.origin.isLoading">
Expand Down Expand Up @@ -180,18 +182,32 @@ export class NzDemoTreeDirTreeComponent implements OnInit {
* @param {} data
*/

openFolder(data: NzTreeNode): void {
openFolder(data: NzTreeNode | NzFormatEmitEvent): void {
// do something if u want
// change node's expand status
if (!data.isExpanded) {
// close to open
data.origin.isLoading = true;
setTimeout(() => {
if (data instanceof NzTreeNode) {
// change node's expand status
if (!data.isExpanded) {
// close to open
data.origin.isLoading = true;
setTimeout(() => {
data.isExpanded = !data.isExpanded;
data.origin.isLoading = false;
}, 500);
} else {
data.isExpanded = !data.isExpanded;
data.origin.isLoading = false;
}, 500);
}
} else {
data.isExpanded = !data.isExpanded;
// change node's expand status
if (!data.node.isExpanded) {
// close to open
data.node.origin.isLoading = true;
setTimeout(() => {
data.node.isExpanded = !data.node.isExpanded;
data.node.origin.isLoading = false;
}, 500);
} else {
data.node.isExpanded = !data.node.isExpanded;
}
}
}

Expand Down
6 changes: 2 additions & 4 deletions components/tree/nz-tree.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ export class NzTreeComponent implements OnInit {
@Input()
set nzSearchValue(value: string) {
this._searchValue = value;
if (value) {
this.nzTreeService.searchExpand(value);
this.nzOnSearchNode.emit(this.nzTreeService.formatEvent('search', null, null));
}
this.nzTreeService.searchExpand(value);
this.nzOnSearchNode.emit(this.nzTreeService.formatEvent('search', null, null));
}

get nzSearchValue(): string {
Expand Down
3 changes: 3 additions & 0 deletions components/tree/nz-tree.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ export class NzTreeService {
*/
searchExpand(value: string): void {
this.matchedNodeList = [];
if (!value) {
return;
}
const loopParent = (node: NzTreeNode) => {
// expand parent node
if (node.getParentNode()) {
Expand Down

0 comments on commit b17647f

Please sign in to comment.