mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-23 09:52:57 +08:00
feat(NumberKeyboard): add focused prop (#4279)
This commit is contained in:
parent
667c4f692c
commit
3264825f77
@ -22,6 +22,7 @@ Vue.use(PasswordInput).use(NumberKeyboard);
|
|||||||
<van-password-input
|
<van-password-input
|
||||||
:value="value"
|
:value="value"
|
||||||
info="Some tips"
|
info="Some tips"
|
||||||
|
:focused="showKeyboard"
|
||||||
@focus="showKeyboard = true"
|
@focus="showKeyboard = true"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@ -61,6 +62,7 @@ export default {
|
|||||||
:value="value"
|
:value="value"
|
||||||
:length="4"
|
:length="4"
|
||||||
:gutter="15"
|
:gutter="15"
|
||||||
|
:focused="showKeyboard"
|
||||||
@focus="showKeyboard = true"
|
@focus="showKeyboard = true"
|
||||||
/>
|
/>
|
||||||
```
|
```
|
||||||
@ -71,6 +73,7 @@ export default {
|
|||||||
<van-password-input
|
<van-password-input
|
||||||
:value="value"
|
:value="value"
|
||||||
:mask="false"
|
:mask="false"
|
||||||
|
:focused="showKeyboard"
|
||||||
@focus="showKeyboard = true"
|
@focus="showKeyboard = true"
|
||||||
/>
|
/>
|
||||||
```
|
```
|
||||||
@ -84,6 +87,7 @@ export default {
|
|||||||
| value | Password value | *string* | `''` | - |
|
| value | Password value | *string* | `''` | - |
|
||||||
| length | Maxlength of password | *number* | `6` | - |
|
| length | Maxlength of password | *number* | `6` | - |
|
||||||
| mask | Whether to mask value | *boolean* | `true` | - |
|
| mask | Whether to mask value | *boolean* | `true` | - |
|
||||||
|
| focused | Whether to show focused cursor | *boolean* | `false` | 2.1.8 |
|
||||||
| info | Bottom info | *string* | - | - |
|
| info | Bottom info | *string* | - | - |
|
||||||
| error-info | Bottom error info | *string* | - | - |
|
| error-info | Bottom error info | *string* | - | - |
|
||||||
| gutter | Gutter of input | *string \| number* | `0` | - |
|
| gutter | Gutter of input | *string \| number* | `0` | - |
|
||||||
|
@ -22,6 +22,7 @@ Vue.use(PasswordInput).use(NumberKeyboard);
|
|||||||
<van-password-input
|
<van-password-input
|
||||||
:value="value"
|
:value="value"
|
||||||
info="密码为 6 位数字"
|
info="密码为 6 位数字"
|
||||||
|
:focused="showKeyboard"
|
||||||
@focus="showKeyboard = true"
|
@focus="showKeyboard = true"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@ -61,6 +62,7 @@ export default {
|
|||||||
:value="value"
|
:value="value"
|
||||||
:length="4"
|
:length="4"
|
||||||
:gutter="15"
|
:gutter="15"
|
||||||
|
:focused="showKeyboard"
|
||||||
@focus="showKeyboard = true"
|
@focus="showKeyboard = true"
|
||||||
/>
|
/>
|
||||||
```
|
```
|
||||||
@ -71,6 +73,7 @@ export default {
|
|||||||
<van-password-input
|
<van-password-input
|
||||||
:value="value"
|
:value="value"
|
||||||
:mask="false"
|
:mask="false"
|
||||||
|
:focused="showKeyboard"
|
||||||
@focus="showKeyboard = true"
|
@focus="showKeyboard = true"
|
||||||
/>
|
/>
|
||||||
```
|
```
|
||||||
@ -82,6 +85,7 @@ export default {
|
|||||||
| value | 密码值 | *string* | `''` | - |
|
| value | 密码值 | *string* | `''` | - |
|
||||||
| length | 密码最大长度 | *number* | `6` | - |
|
| length | 密码最大长度 | *number* | `6` | - |
|
||||||
| mask | 是否隐藏密码内容 | *boolean* | `true` | - |
|
| mask | 是否隐藏密码内容 | *boolean* | `true` | - |
|
||||||
|
| focused | 是否已聚焦,聚焦时会显示光标 | *boolean* | `false` | 2.1.8 |
|
||||||
| info | 输入框下方文字提示 | *string* | - | - |
|
| info | 输入框下方文字提示 | *string* | - | - |
|
||||||
| error-info | 输入框下方错误提示 | *string* | - | - |
|
| error-info | 输入框下方错误提示 | *string* | - | - |
|
||||||
| gutter | 输入框格子之间的间距,如 `20px` `2em`,默认单位为`px` | *string \| number* | `0` | - |
|
| gutter | 输入框格子之间的间距,如 `20px` `2em`,默认单位为`px` | *string \| number* | `0` | - |
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
<van-password-input
|
<van-password-input
|
||||||
:value="value1"
|
:value="value1"
|
||||||
:info="$t('info')"
|
:info="$t('info')"
|
||||||
|
:focused="keyboard === 'value1'"
|
||||||
@focus="keyboard = 'value1'"
|
@focus="keyboard = 'value1'"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@ -20,6 +21,7 @@
|
|||||||
:value="value2"
|
:value="value2"
|
||||||
:length="4"
|
:length="4"
|
||||||
gutter="15"
|
gutter="15"
|
||||||
|
:focused="keyboard === 'value2'"
|
||||||
@focus="keyboard = 'value2'"
|
@focus="keyboard = 'value2'"
|
||||||
/>
|
/>
|
||||||
</demo-block>
|
</demo-block>
|
||||||
@ -28,6 +30,7 @@
|
|||||||
<van-password-input
|
<van-password-input
|
||||||
:value="value3"
|
:value="value3"
|
||||||
:mask="false"
|
:mask="false"
|
||||||
|
:focused="keyboard === 'value3'"
|
||||||
@focus="keyboard = 'value3'"
|
@focus="keyboard = 'value3'"
|
||||||
/>
|
/>
|
||||||
</demo-block>
|
</demo-block>
|
||||||
|
@ -51,4 +51,29 @@
|
|||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&__cursor {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
width: @number-keyboard-cursor-width;
|
||||||
|
height: @number-keyboard-cursor-height;
|
||||||
|
background-color: @number-keyboard-cursor-color;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
animation: @number-keyboard-cursor-animation-duration van-cursor-flicker infinite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes van-cursor-flicker {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
50% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ export type PasswordInputProps = {
|
|||||||
value: string;
|
value: string;
|
||||||
length: number;
|
length: number;
|
||||||
gutter: number;
|
gutter: number;
|
||||||
|
focused?: boolean;
|
||||||
errorInfo?: string;
|
errorInfo?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ function PasswordInput(
|
|||||||
for (let i = 0; i < props.length; i++) {
|
for (let i = 0; i < props.length; i++) {
|
||||||
const char = props.value[i];
|
const char = props.value[i];
|
||||||
const showBorder = i !== 0 && !props.gutter;
|
const showBorder = i !== 0 && !props.gutter;
|
||||||
|
const showCursor = props.focused && i === props.value.length;
|
||||||
|
|
||||||
let style;
|
let style;
|
||||||
if (i !== 0 && props.gutter) {
|
if (i !== 0 && props.gutter) {
|
||||||
@ -38,6 +40,7 @@ function PasswordInput(
|
|||||||
Points.push(
|
Points.push(
|
||||||
<li class={{ [BORDER_LEFT]: showBorder }} style={style}>
|
<li class={{ [BORDER_LEFT]: showBorder }} style={style}>
|
||||||
{props.mask ? <i style={{ visibility: char ? 'visible' : 'hidden' }} /> : char}
|
{props.mask ? <i style={{ visibility: char ? 'visible' : 'hidden' }} /> : char}
|
||||||
|
{showCursor && <div class={bem('cursor')} />}
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -62,6 +65,7 @@ function PasswordInput(
|
|||||||
PasswordInput.props = {
|
PasswordInput.props = {
|
||||||
info: String,
|
info: String,
|
||||||
gutter: [Number, String],
|
gutter: [Number, String],
|
||||||
|
focused: Boolean,
|
||||||
errorInfo: String,
|
errorInfo: String,
|
||||||
mask: {
|
mask: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
|
@ -8,7 +8,9 @@ exports[`renders demo correctly 1`] = `
|
|||||||
<li class=""><i style="visibility: visible;"></i></li>
|
<li class=""><i style="visibility: visible;"></i></li>
|
||||||
<li class="van-hairline--left"><i style="visibility: visible;"></i></li>
|
<li class="van-hairline--left"><i style="visibility: visible;"></i></li>
|
||||||
<li class="van-hairline--left"><i style="visibility: visible;"></i></li>
|
<li class="van-hairline--left"><i style="visibility: visible;"></i></li>
|
||||||
<li class="van-hairline--left"><i style="visibility: hidden;"></i></li>
|
<li class="van-hairline--left"><i style="visibility: hidden;"></i>
|
||||||
|
<div class="van-password-input__cursor"></div>
|
||||||
|
</li>
|
||||||
<li class="van-hairline--left"><i style="visibility: hidden;"></i></li>
|
<li class="van-hairline--left"><i style="visibility: hidden;"></i></li>
|
||||||
<li class="van-hairline--left"><i style="visibility: hidden;"></i></li>
|
<li class="van-hairline--left"><i style="visibility: hidden;"></i></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -380,6 +380,10 @@
|
|||||||
@number-keyboard-close-font-size: @font-size-md;
|
@number-keyboard-close-font-size: @font-size-md;
|
||||||
@number-keyboard-button-text-color: @white;
|
@number-keyboard-button-text-color: @white;
|
||||||
@number-keyboard-button-background-color: @blue;
|
@number-keyboard-button-background-color: @blue;
|
||||||
|
@number-keyboard-cursor-color: @text-color;
|
||||||
|
@number-keyboard-cursor-width: 1px;
|
||||||
|
@number-keyboard-cursor-height: 40%;
|
||||||
|
@number-keyboard-cursor-animation-duration: 1s;
|
||||||
|
|
||||||
// Overlay
|
// Overlay
|
||||||
@overlay-background-color: rgba(0, 0, 0, 0.7);
|
@overlay-background-color: rgba(0, 0, 0, 0.7);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user