mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
feat(field): add prop extra-event-params support (#5184)
* feat(field): add prop extra support * feat(field): adjust extra params to extra-to-params
This commit is contained in:
parent
0c372115da
commit
d14ac6027a
@ -257,14 +257,15 @@ Page({
|
|||||||
| disable-default-padding | 是否去掉 iOS 下的默认内边距,只对 textarea 有效 | _boolean_ | `true` |
|
| disable-default-padding | 是否去掉 iOS 下的默认内边距,只对 textarea 有效 | _boolean_ | `true` |
|
||||||
| cursor | 指定 focus 时的光标位置 | _number_ | `-1` |
|
| cursor | 指定 focus 时的光标位置 | _number_ | `-1` |
|
||||||
| clear-trigger `v1.8.4` | 显示清除图标的时机,`always` 表示输入框不为空时展示,<br>`focus` 表示输入框聚焦且不为空时展示 | _string_ | `focus` |
|
| clear-trigger `v1.8.4` | 显示清除图标的时机,`always` 表示输入框不为空时展示,<br>`focus` 表示输入框聚焦且不为空时展示 | _string_ | `focus` |
|
||||||
| always-embed `v1.9.2` | 强制 input 处于同层状态,默认 focus 时 input 会切到非同层状态 (仅在 iOS 下生效) | _boolean_ | `false` |
|
| always-embed `v1.9.2` | 强制 input 处于同层状态,默认 focus 时 input 会切到非同层状态 (仅在 iOS 下生效) | _boolean_ | `false` |
|
||||||
|
| extra-event-params `v1.10.12` | 开启事件增强模式,会在 input 和 change 事件额外提供 `cursor` 和 `keyCode` 参数,计划在下一个大版本作为默认行为 | _boolean_ | `false` |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
| 事件 | 说明 | 回调参数 |
|
| 事件 | 说明 | 回调参数 |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| bind:input | 输入内容时触发 | event.detail: 当前输入值 |
|
| bind:input | 输入内容时触发 | event.detail: 当前输入值; 在 extra-event-params 为 `true` 时, event.detail.value: 当前输入值, event.detail.cursor: 光标位置, event.detail.keyCode: 键值 |
|
||||||
| bind:change | 输入内容时触发 | event.detail: 当前输入值 |
|
| bind:change | 输入内容时触发 | event.detail: 当前输入值; 在 extra-event-params 为 `true` 时, event.detail.value: 当前输入值, event.detail.cursor: 光标位置, event.detail.keyCode: 键值 |
|
||||||
| bind:confirm | 点击完成按钮时触发 | event.detail: 当前输入值 |
|
| bind:confirm | 点击完成按钮时触发 | event.detail: 当前输入值 |
|
||||||
| bind:click-icon | 点击尾部图标时触发 | - |
|
| bind:click-icon | 点击尾部图标时触发 | - |
|
||||||
| bind:focus | 输入框聚焦时触发 | event.detail.value: 当前输入值; <br>event.detail.height: 键盘高度 |
|
| bind:focus | 输入框聚焦时触发 | event.detail.value: 当前输入值; <br>event.detail.height: 键盘高度 |
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { nextTick } from '../common/utils';
|
import { nextTick } from '../common/utils';
|
||||||
import { VantComponent } from '../common/component';
|
import { VantComponent } from '../common/component';
|
||||||
import { commonProps, inputProps, textareaProps } from './props';
|
import { commonProps, inputProps, textareaProps } from './props';
|
||||||
|
import { InputDetails } from './types';
|
||||||
|
|
||||||
VantComponent({
|
VantComponent({
|
||||||
field: true,
|
field: true,
|
||||||
@ -53,6 +54,10 @@ VantComponent({
|
|||||||
type: String,
|
type: String,
|
||||||
value: 'clear',
|
value: 'clear',
|
||||||
},
|
},
|
||||||
|
extraEventParams: {
|
||||||
|
type: Boolean,
|
||||||
|
value: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
data: {
|
data: {
|
||||||
@ -72,7 +77,8 @@ VantComponent({
|
|||||||
|
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.setShowClear();
|
this.setShowClear();
|
||||||
this.emitChange();
|
|
||||||
|
this.emitChange(event.detail);
|
||||||
},
|
},
|
||||||
|
|
||||||
onFocus(
|
onFocus(
|
||||||
@ -105,7 +111,7 @@ VantComponent({
|
|||||||
this.setShowClear();
|
this.setShowClear();
|
||||||
|
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
this.emitChange();
|
this.emitChange({ value: '' });
|
||||||
this.$emit('clear', '');
|
this.$emit('clear', '');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -119,7 +125,7 @@ VantComponent({
|
|||||||
this.$emit('confirm', value);
|
this.$emit('confirm', value);
|
||||||
},
|
},
|
||||||
|
|
||||||
setValue(value) {
|
setValue(value: string) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.setShowClear();
|
this.setShowClear();
|
||||||
|
|
||||||
@ -127,7 +133,7 @@ VantComponent({
|
|||||||
this.setData({ innerValue: '' });
|
this.setData({ innerValue: '' });
|
||||||
}
|
}
|
||||||
|
|
||||||
this.emitChange();
|
this.emitChange({ value });
|
||||||
},
|
},
|
||||||
|
|
||||||
onLineChange(event: WechatMiniprogram.TextareaLineChange) {
|
onLineChange(event: WechatMiniprogram.TextareaLineChange) {
|
||||||
@ -142,12 +148,16 @@ VantComponent({
|
|||||||
this.$emit('keyboardheightchange', event.detail);
|
this.$emit('keyboardheightchange', event.detail);
|
||||||
},
|
},
|
||||||
|
|
||||||
emitChange() {
|
emitChange(detail: InputDetails) {
|
||||||
this.setData({ value: this.value });
|
const { extraEventParams } = this.data;
|
||||||
|
|
||||||
|
this.setData({ value: detail.value });
|
||||||
|
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
this.$emit('input', this.value);
|
const data = extraEventParams ? detail : detail.value;
|
||||||
this.$emit('change', this.value);
|
|
||||||
|
this.$emit('input', data);
|
||||||
|
this.$emit('change', data);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
8
packages/field/types.ts
Normal file
8
packages/field/types.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
export interface InputDetails {
|
||||||
|
/** 输入框内容 */
|
||||||
|
value: string;
|
||||||
|
/** 光标位置 */
|
||||||
|
cursor?: number;
|
||||||
|
/** keyCode 为键值 (目前工具还不支持返回keyCode参数) `2.1.0` 起支持 */
|
||||||
|
keyCode?: number;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user