mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[improvement] PasswordInput: functional (#2694)
This commit is contained in:
parent
305dc19ceb
commit
061382014d
@ -2,50 +2,50 @@ import { use } from '../utils';
|
|||||||
|
|
||||||
const [sfc, bem] = use('password-input');
|
const [sfc, bem] = use('password-input');
|
||||||
|
|
||||||
export default sfc({
|
export default sfc(
|
||||||
props: {
|
{
|
||||||
info: String,
|
props: {
|
||||||
errorInfo: String,
|
info: String,
|
||||||
value: {
|
errorInfo: String,
|
||||||
type: String,
|
value: {
|
||||||
default: ''
|
type: String,
|
||||||
},
|
default: ''
|
||||||
length: {
|
},
|
||||||
type: Number,
|
length: {
|
||||||
default: 6
|
type: Number,
|
||||||
}
|
default: 6
|
||||||
},
|
|
||||||
|
|
||||||
computed: {
|
|
||||||
points() {
|
|
||||||
const arr = [];
|
|
||||||
for (let i = 0; i < this.length; i++) {
|
|
||||||
arr[i] = this.value[i] ? 'visible' : 'hidden';
|
|
||||||
}
|
}
|
||||||
return arr;
|
},
|
||||||
|
|
||||||
|
render(h, context) {
|
||||||
|
const { props, listeners } = context;
|
||||||
|
const info = props.errorInfo || props.info;
|
||||||
|
|
||||||
|
const Points = [];
|
||||||
|
for (let i = 0; i < props.length; i++) {
|
||||||
|
Points.push(
|
||||||
|
<li class="van-hairline">
|
||||||
|
<i style={{ visibility: props.value[i] ? 'visible' : 'hidden' }} />
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div class={bem()}>
|
||||||
|
<ul
|
||||||
|
class={[bem('security'), 'van-hairline--surround']}
|
||||||
|
onTouchstart={event => {
|
||||||
|
event.stopPropagation();
|
||||||
|
listeners.focus && listeners.focus();
|
||||||
|
}}
|
||||||
|
{...context.data}
|
||||||
|
>
|
||||||
|
{Points}
|
||||||
|
</ul>
|
||||||
|
{info && <div class={bem(props.errorInfo ? 'error-info' : 'info')}>{info}</div>}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
true
|
||||||
render(h) {
|
);
|
||||||
const info = this.errorInfo || this.info;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div class={bem()}>
|
|
||||||
<ul
|
|
||||||
class={[bem('security'), 'van-hairline--surround']}
|
|
||||||
onTouchstart={event => {
|
|
||||||
event.stopPropagation();
|
|
||||||
this.$emit('focus');
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{this.points.map(visibility => (
|
|
||||||
<li class="van-hairline">
|
|
||||||
<i style={{ visibility }} />
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
{info && <div class={bem(this.errorInfo ? 'error-info' : 'info')}>{info}</div>}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
16
packages/password-input/test/index.spec.js
Normal file
16
packages/password-input/test/index.spec.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import PasswordInput from '..';
|
||||||
|
import { mount } from '../../../test/utils';
|
||||||
|
|
||||||
|
test('focus event', () => {
|
||||||
|
const focus = jest.fn();
|
||||||
|
const wrapper = mount(PasswordInput, {
|
||||||
|
context: {
|
||||||
|
on: {
|
||||||
|
focus
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
wrapper.find('.van-password-input__security').trigger('touchstart');
|
||||||
|
expect(focus.mock.calls.length).toEqual(1);
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user