feat(Field): add format-trigger prop (#6566)

This commit is contained in:
neverland
2020-06-18 20:57:42 +08:00
committed by GitHub
parent f2543b5dfa
commit 95313ef459
6 changed files with 87 additions and 27 deletions
@@ -112,7 +112,13 @@ exports[`renders demo correctly 1`] = `
<div class="van-cell van-field">
<div class="van-cell__title van-field__label"><span>文本</span></div>
<div class="van-cell__value van-field__value">
<div class="van-field__body"><input type="text" placeholder="格式化输入内容" class="van-field__control"></div>
<div class="van-field__body"><input type="text" placeholder="在输入时执行格式化" class="van-field__control"></div>
</div>
</div>
<div class="van-cell van-field">
<div class="van-cell__title van-field__label"><span>文本</span></div>
<div class="van-cell__value van-field__value">
<div class="van-field__body"><input type="text" placeholder="在失焦时执行格式化" class="van-field__control"></div>
</div>
</div>
</div>
+23
View File
@@ -297,6 +297,29 @@ test('formatter prop', () => {
expect(wrapper.emitted('input')[1][0]).toEqual('efg');
});
test('format-trigger prop', () => {
const wrapper = mount(Field, {
propsData: {
value: 'abc123',
formatTrigger: 'onBlur',
formatter: (value) => value.replace(/\d/g, ''),
},
});
wrapper.vm.$on('input', (value) => {
wrapper.setProps({ value });
});
expect(wrapper.emitted('input')[0][0]).toEqual('abc');
const input = wrapper.find('input');
input.element.value = '123efg';
input.trigger('input');
expect(wrapper.emitted('input')[1][0]).toEqual('123efg');
input.trigger('blur');
expect(wrapper.emitted('input')[2][0]).toEqual('efg');
});
test('reach max word-limit', () => {
const wrapper = mount(Field, {
propsData: {