feat(Field): add formatter prop (#5534)

This commit is contained in:
neverland
2020-01-09 20:52:20 +08:00
committed by GitHub
parent 47c24e192c
commit 9452444a7d
6 changed files with 200 additions and 94 deletions
@@ -115,6 +115,16 @@ exports[`renders demo correctly 1`] = `
</div>
</div>
</div>
<div>
<div class="van-cell-group van-hairline--top-bottom">
<div class="van-cell van-field">
<div class="van-cell__title van-field__label"><span>文本</span></div>
<div class="van-cell__value">
<div class="van-field__body"><input type="text" placeholder="格式化输入内容" class="van-field__control"></div>
</div>
</div>
</div>
</div>
<div>
<div class="van-cell-group van-hairline--top-bottom">
<div class="van-cell van-field">
+18
View File
@@ -262,3 +262,21 @@ test('arrow-direction prop', () => {
});
expect(wrapper).toMatchSnapshot();
});
test('formatter prop', () => {
const wrapper = mount(Field, {
propsData: {
value: 'abc123',
formatter: (value) => value.replace(/\d/g, '')
}
});
const input = wrapper.find('input');
input.trigger('input');
expect(wrapper.emitted('input')[0][0]).toEqual('abc');
input.element.value = '123efg';
input.trigger('input');
expect(wrapper.emitted('input')[1][0]).toEqual('efg');
});