[new feature] NumberKeyboard: add maxlength prop (#3532)

This commit is contained in:
neverland
2019-06-17 15:33:25 +08:00
committed by GitHub
parent ce3dfc859a
commit 8331b7597d
6 changed files with 34 additions and 4 deletions
@@ -25,7 +25,6 @@ exports[`renders demo correctly 1`] = `
</div>
</div>
<div class="van-number-keyboard van-number-keyboard--default van-number-keyboard--safe-area-inset-bottom" style="z-index: 100; display: none;" name="van-slide-up">
<div class="van-number-keyboard__title van-hairline--top"><span role="button" tabindex="0" class="van-number-keyboard__close">完成</span></div>
<div class="van-number-keyboard__body"><i role="button" tabindex="0" class="van-hairline van-key">1</i><i role="button" tabindex="0" class="van-hairline van-key">2</i><i role="button" tabindex="0" class="van-hairline van-key">3</i><i role="button" tabindex="0" class="van-hairline van-key">4</i><i role="button" tabindex="0" class="van-hairline van-key">5</i><i role="button" tabindex="0" class="van-hairline van-key">6</i><i role="button" tabindex="0" class="van-hairline van-key">7</i><i role="button" tabindex="0" class="van-hairline van-key">8</i><i role="button" tabindex="0" class="van-hairline van-key">9</i><i role="button" tabindex="0" class="van-hairline van-key van-key--gray"></i><i role="button" tabindex="0" class="van-hairline van-key">0</i><i role="button" tabindex="0" class="van-hairline van-key van-key--gray van-key--delete">删除</i></div>
</div>
</div>
+24 -1
View File
@@ -127,7 +127,7 @@ test('focus on key', () => {
expect(wrapper).toMatchSnapshot();
});
test('controlled mode', () => {
test('bind value', () => {
const wrapper = mount(NumberKeyboard, {
propsData: {
value: ''
@@ -148,3 +148,26 @@ test('controlled mode', () => {
keys.at(11).trigger('click');
expect(wrapper.vm.value).toEqual('1');
});
test('maxlength', () => {
const onInput = jest.fn();
const wrapper = mount(NumberKeyboard, {
propsData: {
value: '',
maxlength: 1
},
listeners: {
input: onInput,
'update:value': value => {
wrapper.setProps({ value });
}
}
});
const keys = wrapper.findAll('.van-key');
keys.at(0).trigger('click');
keys.at(1).trigger('click');
expect(wrapper.vm.value).toEqual('1');
expect(onInput).toHaveBeenCalledTimes(1);
});