[improvement] Search: support form-field (#480)

This commit is contained in:
neverland 2018-08-29 16:56:12 +08:00 committed by GitHub
parent c8836b8d6f
commit 468ecdefa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 26 deletions

16
dist/search/index.js vendored
View File

@ -1,4 +1,6 @@
Component({
behaviors: ['wx://form-field'],
externalClasses: ['custom-class', 'cancel-class'],
options: {
@ -12,12 +14,6 @@ Component({
showAction: Boolean,
useActionSlot: Boolean,
placeholder: String,
value: {
type: String,
observer(currentValue) {
this.setData({ currentValue });
}
},
background: {
type: String,
value: '#f2f2f2'
@ -28,23 +24,19 @@ Component({
}
},
attached() {
this.setData({ currentValue: this.data.value });
},
methods: {
onChange(event) {
this.triggerEvent('change', event.detail);
},
onCancel() {
this.setData({ currentValue: '' });
this.setData({ value: '' });
this.triggerEvent('cancel');
this.triggerEvent('change', '');
},
onSearch() {
this.triggerEvent('search', this.data.currentValue);
this.triggerEvent('search', this.data.value);
},
onFocus() {

View File

@ -9,7 +9,7 @@
left-icon="search"
border="{{ false }}"
confirm-type="search"
value="{{ currentValue }}"
value="{{ value }}"
disabled="{{ disabled }}"
readonly="{{ readony }}"
maxlength="{{ maxlength }}"

View File

@ -47,6 +47,7 @@ Search 支持自定义右侧取消按钮,使用名字为 action 的 slot 即
| 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------|
| name | 在表单内提交时的标识符 | `String` | - |
| value | 当前输入的值 | `String | Number` | - |
| background | 搜索框背景色 | `String` | `#f2f2f2` |
| show-action | 是否在搜索框右侧显示取消按钮 | `Boolean` | `false` |

View File

@ -1,4 +1,6 @@
Component({
behaviors: ['wx://form-field'],
externalClasses: ['custom-class', 'cancel-class'],
options: {
@ -12,12 +14,6 @@ Component({
showAction: Boolean,
useActionSlot: Boolean,
placeholder: String,
value: {
type: String,
observer(currentValue) {
this.setData({ currentValue });
}
},
background: {
type: String,
value: '#f2f2f2'
@ -28,23 +24,19 @@ Component({
}
},
attached() {
this.setData({ currentValue: this.data.value });
},
methods: {
onChange(event) {
this.triggerEvent('change', event.detail);
},
onCancel() {
this.setData({ currentValue: '' });
this.setData({ value: '' });
this.triggerEvent('cancel');
this.triggerEvent('change', '');
},
onSearch() {
this.triggerEvent('search', this.data.currentValue);
this.triggerEvent('search', this.data.value);
},
onFocus() {

View File

@ -9,7 +9,7 @@
left-icon="search"
border="{{ false }}"
confirm-type="search"
value="{{ currentValue }}"
value="{{ value }}"
disabled="{{ disabled }}"
readonly="{{ readony }}"
maxlength="{{ maxlength }}"