mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[new feature] NumberKeyboard: add hideOnClickOutside & closeButtonText props (#458)
This commit is contained in:
parent
021d30efb1
commit
993aaad499
@ -5,12 +5,10 @@
|
|||||||
{{ $t('button1') }}
|
{{ $t('button1') }}
|
||||||
</van-button>
|
</van-button>
|
||||||
|
|
||||||
<van-button @touchstart.native.stop="showKeyboard = false">
|
|
||||||
{{ $t('button2') }}
|
|
||||||
</van-button>
|
|
||||||
|
|
||||||
<van-number-keyboard
|
<van-number-keyboard
|
||||||
:show="showKeyboard"
|
:show="showKeyboard"
|
||||||
|
:closeButtonText="$t('close')"
|
||||||
|
extraKey="."
|
||||||
@blur="showKeyboard = false"
|
@blur="showKeyboard = false"
|
||||||
@input="onInput"
|
@input="onInput"
|
||||||
@delete="onDelete"
|
@delete="onDelete"
|
||||||
@ -24,11 +22,13 @@ export default {
|
|||||||
i18n: {
|
i18n: {
|
||||||
'zh-CN': {
|
'zh-CN': {
|
||||||
button1: '弹出键盘',
|
button1: '弹出键盘',
|
||||||
button2: '收起键盘'
|
button2: '收起键盘',
|
||||||
|
close: '完成'
|
||||||
},
|
},
|
||||||
'en-US': {
|
'en-US': {
|
||||||
button1: 'Show Keyboard',
|
button1: 'Show Keyboard',
|
||||||
button2: 'Hide Keyboard'
|
button2: 'Hide Keyboard',
|
||||||
|
close: 'Close'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -16,12 +16,10 @@ Vue.use(NumberKeyboard);
|
|||||||
Show Keyboard
|
Show Keyboard
|
||||||
</van-button>
|
</van-button>
|
||||||
|
|
||||||
<van-button @touchstart.native.stop="showKeyboard = false">
|
|
||||||
Hide Keyboard
|
|
||||||
</van-button>
|
|
||||||
|
|
||||||
<van-number-keyboard
|
<van-number-keyboard
|
||||||
|
extraKey="."
|
||||||
:show="showKeyboard"
|
:show="showKeyboard"
|
||||||
|
closeButtonText="Close"
|
||||||
@blur="showKeyboard = false"
|
@blur="showKeyboard = false"
|
||||||
@input="onInput"
|
@input="onInput"
|
||||||
@delete="onDelete"
|
@delete="onDelete"
|
||||||
@ -53,10 +51,12 @@ export default {
|
|||||||
|-----------|-----------|-----------|-------------|-------------|
|
|-----------|-----------|-----------|-------------|-------------|
|
||||||
| show | Whether to show keyboard | `Boolean` | - | - |
|
| show | Whether to show keyboard | `Boolean` | - | - |
|
||||||
| title | Keyboard title | `String` | - | - |
|
| title | Keyboard title | `String` | - | - |
|
||||||
| extraKey | Content of bottom left key | `String` | `''` | - |
|
|
||||||
| zIndex | Keyboard z-index | `Number` | `100` | - |
|
| zIndex | Keyboard z-index | `Number` | `100` | - |
|
||||||
|
| extraKey | Content of bottom left key | `String` | `''` | - |
|
||||||
|
| closeButtonText | Close button text | `String` | `-` | - |
|
||||||
| transition | Whether to show transition animation | `Boolean` | `true` | - |
|
| transition | Whether to show transition animation | `Boolean` | `true` | - |
|
||||||
| showDeleteKey | Whether to show delete button | `Boolean` | `true` | - |
|
| showDeleteKey | Whether to show delete button | `Boolean` | `true` | - |
|
||||||
|
| hideOnClickOutside | Whether to hide keyboard when click outside | `Boolean` | `true` | - |
|
||||||
|
|
||||||
### Event
|
### Event
|
||||||
|
|
||||||
|
@ -16,12 +16,10 @@ Vue.use(NumberKeyboard);
|
|||||||
弹出键盘
|
弹出键盘
|
||||||
</van-button>
|
</van-button>
|
||||||
|
|
||||||
<van-button @touchstart.native.stop="showKeyboard = false">
|
|
||||||
收起键盘
|
|
||||||
</van-button>
|
|
||||||
|
|
||||||
<van-number-keyboard
|
<van-number-keyboard
|
||||||
|
extraKey="."
|
||||||
:show="showKeyboard"
|
:show="showKeyboard"
|
||||||
|
closeButtonText="完成"
|
||||||
@blur="showKeyboard = false"
|
@blur="showKeyboard = false"
|
||||||
@input="onInput"
|
@input="onInput"
|
||||||
@delete="onDelete"
|
@delete="onDelete"
|
||||||
@ -53,10 +51,12 @@ export default {
|
|||||||
|-----------|-----------|-----------|-------------|-------------|
|
|-----------|-----------|-----------|-------------|-------------|
|
||||||
| show | 是否显示键盘 | `Boolean` | - | - |
|
| show | 是否显示键盘 | `Boolean` | - | - |
|
||||||
| title | 键盘标题 | `String` | - | - |
|
| title | 键盘标题 | `String` | - | - |
|
||||||
| extraKey | 左下角按键内容 | `String` | `''` | - |
|
|
||||||
| zIndex | 键盘 z-index | `Number` | `100` | - |
|
| zIndex | 键盘 z-index | `Number` | `100` | - |
|
||||||
|
| extraKey | 左下角按键内容 | `String` | `''` | - |
|
||||||
|
| closeButtonText | 关闭按钮文字,空则不展示 | `String` | `-` | - |
|
||||||
| transition | 是否开启过场动画 | `Boolean` | `true` | - |
|
| transition | 是否开启过场动画 | `Boolean` | `true` | - |
|
||||||
| showDeleteKey | 是否展示删除按钮 | `Boolean` | `true` | - |
|
| showDeleteKey | 是否展示删除按钮 | `Boolean` | `true` | - |
|
||||||
|
| hideOnClickOutside | 点击外部时是否收起键盘 | `Boolean` | `true` | - |
|
||||||
|
|
||||||
### Event
|
### Event
|
||||||
|
|
||||||
|
@ -9,12 +9,18 @@
|
|||||||
@touchend="blurKey"
|
@touchend="blurKey"
|
||||||
@touchcancel="blurKey"
|
@touchcancel="blurKey"
|
||||||
@animationend="onAnimationEnd"
|
@animationend="onAnimationEnd"
|
||||||
|
@webkitAnimationEnd="onAnimationEnd"
|
||||||
>
|
>
|
||||||
<div class="van-number-keyboard__title van-hairline--top" v-if="title">
|
<div class="van-number-keyboard__title van-hairline--top" v-if="title || closeButtonText">
|
||||||
<span>{{ title }}</span>
|
<span>{{ title }}</span>
|
||||||
|
<span
|
||||||
|
class="van-number-keyboard__close"
|
||||||
|
v-text="closeButtonText"
|
||||||
|
@click="blurKeyboard"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<i
|
<i
|
||||||
v-for="(key, index) in keys"
|
v-for="(key, index) in keys"
|
||||||
v-text="key"
|
v-text="key"
|
||||||
:data-key="index"
|
:data-key="index"
|
||||||
class="van-hairline"
|
class="van-hairline"
|
||||||
@ -35,6 +41,11 @@ export default create({
|
|||||||
|
|
||||||
props: {
|
props: {
|
||||||
show: Boolean,
|
show: Boolean,
|
||||||
|
closeButtonText: String,
|
||||||
|
theme: {
|
||||||
|
type: String,
|
||||||
|
default: 'default'
|
||||||
|
},
|
||||||
extraKey: {
|
extraKey: {
|
||||||
type: String,
|
type: String,
|
||||||
default: ''
|
default: ''
|
||||||
@ -51,6 +62,10 @@ export default create({
|
|||||||
showDeleteKey: {
|
showDeleteKey: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true
|
default: true
|
||||||
|
},
|
||||||
|
hideOnClickOutside: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -103,7 +118,7 @@ export default create({
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
handler(action) {
|
handler(action) {
|
||||||
if (action !== this.handlerStatus) {
|
if (action !== this.handlerStatus && this.hideOnClickOutside) {
|
||||||
this.handlerStatus = action;
|
this.handlerStatus = action;
|
||||||
document.body[(action ? 'add' : 'remove') + 'EventListener']('touchstart', this.blurKeyboard);
|
document.body[(action ? 'add' : 'remove') + 'EventListener']('touchstart', this.blurKeyboard);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,21 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
color: $gray-dark;
|
color: $gray-dark;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
line-height: 25px;
|
height: 30px;
|
||||||
|
line-height: 30px;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__close {
|
||||||
|
right: 0;
|
||||||
|
color: $blue;
|
||||||
|
font-size: 14px;
|
||||||
|
padding: 0 15px;
|
||||||
|
position: absolute;
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
background-color: $active-color;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i {
|
i {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user