forked from NG-ZORRO/ng-zorro-antd
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cascader): add cascader search (NG-ZORRO#1873)
close NG-ZORRO#1773
- Loading branch information
Showing
10 changed files
with
474 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "chrome", | ||
"request": "launch", | ||
"name": "Chrome", | ||
"url": "http://localhost:9876", | ||
"webRoot": "${workspaceRoot}" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
order: 11 | ||
title: | ||
zh-CN: 搜索 | ||
en-US: Search | ||
--- | ||
|
||
## zh-CN | ||
|
||
可以直接搜索选项并选择。 | ||
|
||
## en-US | ||
|
||
Search and select an option directly. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// tslint:disable:no-any | ||
import { Component, OnInit } from '@angular/core'; | ||
|
||
const options = [ { | ||
value: 'zhejiang', | ||
label: 'Zhejiang', | ||
children: [ { | ||
value: 'hangzhou', | ||
label: 'Hangzhou', | ||
children: [ { | ||
value: 'xihu', | ||
label: 'West Lake', | ||
isLeaf: true | ||
} ] | ||
}, { | ||
value: 'ningbo', | ||
label: 'Ningbo', | ||
isLeaf: true, | ||
disabled: true | ||
} ] | ||
}, { | ||
value: 'jiangsu', | ||
label: 'Jiangsu', | ||
children: [ { | ||
value: 'nanjing', | ||
label: 'Nanjing', | ||
children: [ { | ||
value: 'zhonghuamen', | ||
label: 'Zhong Hua Men', | ||
isLeaf: true | ||
} ] | ||
} ] | ||
} ]; | ||
|
||
const otherOptions = [ { | ||
value: 'fujian', | ||
label: 'Fujian', | ||
children: [ { | ||
value: 'xiamen', | ||
label: 'Xiamen', | ||
children: [ { | ||
value: 'Kulangsu', | ||
label: 'Kulangsu', | ||
isLeaf: true | ||
} ] | ||
} ] | ||
}, { | ||
value: 'guangxi', | ||
label: 'Guangxi', | ||
children: [ { | ||
value: 'guilin', | ||
label: 'Guilin', | ||
children: [ { | ||
value: 'Lijiang', | ||
label: 'Li Jiang River', | ||
isLeaf: true | ||
} ] | ||
} ] | ||
} ]; | ||
|
||
@Component({ | ||
selector: 'nz-demo-cascader-search', | ||
template: ` | ||
<nz-cascader | ||
[nzOptions]="nzOptions" | ||
[(ngModel)]="values" | ||
[nzShowSearch]="true" | ||
(ngModelChange)="onChanges($event)"> | ||
</nz-cascader> | ||
| ||
<a href="javascript:;" (click)="changeNzOptions()" class="change-options"> | ||
Change Options | ||
</a> | ||
`, | ||
styles: [ | ||
` | ||
.ant-cascader-picker { | ||
width: 300px; | ||
} | ||
.change-options { | ||
display: inline-block; | ||
font-size: 12px; | ||
margin-top: 8px; | ||
} | ||
` | ||
] | ||
}) | ||
export class NzDemoCascaderSearchComponent implements OnInit { | ||
/** init data */ | ||
public nzOptions = null; | ||
|
||
/** ngModel value */ | ||
public values: any[] = null; | ||
|
||
ngOnInit(): void { | ||
// let's set nzOptions in a asynchronous way | ||
setTimeout(() => { | ||
this.nzOptions = options; | ||
}, 100); | ||
} | ||
|
||
public changeNzOptions(): void { | ||
if (this.nzOptions === options) { | ||
this.nzOptions = otherOptions; | ||
} else { | ||
this.nzOptions = options; | ||
} | ||
} | ||
|
||
public onChanges(values: any): void { | ||
console.log(values, this.values); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.