Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] fix(module: tree): fix nzOnSearchChange & folder tree demo #1602

Merged
merged 1 commit into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 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 @@ -54,15 +56,15 @@ import { NzFormatEmitEvent, NzTreeNode } from 'ng-zorro-antd';

.custom-node {
cursor: pointer;
line-height: 30px;
line-height: 26px;
margin-left: 4px;
display: inline-block;
margin: 0 -1000px;
padding: 0 1000px;
}

.active {
background: #1890ff;
background: #1890FF;
color: #fff;
}

Expand All @@ -78,7 +80,7 @@ import { NzFormatEmitEvent, NzTreeNode } from 'ng-zorro-antd';

.file-desc, .folder-desc {
padding: 2px 8px;
background: rgba(0,0,0,.15);
background: #87CEFF;
color: #FFFFFF;
}
` ]
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