[bugfix] Field: allow negative number when type is number (#889)

This commit is contained in:
neverland 2018-04-18 16:09:28 +08:00 committed by GitHub
parent 602f8e0b50
commit b206409b8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -115,7 +115,7 @@ export default create({
if (this.type === 'number') { if (this.type === 'number') {
const { keyCode } = event; const { keyCode } = event;
const allowPoint = this.value.indexOf('.') === -1; const allowPoint = this.value.indexOf('.') === -1;
const isValidKey = (keyCode >= 48 && keyCode <= 57) || (keyCode === 46 && allowPoint); const isValidKey = (keyCode >= 48 && keyCode <= 57) || (keyCode === 46 && allowPoint) || keyCode === 45;
if (!isValidKey) { if (!isValidKey) {
event.preventDefault(); event.preventDefault();
} }
@ -129,6 +129,7 @@ export default create({
} }
const el = this.$refs.textarea; const el = this.$refs.textarea;
/* istanbul ignore if */
if (!el) { if (!el) {
return; return;
} }

View File

@ -57,12 +57,13 @@ describe('Field', () => {
it('create a textarea field', (done) => { it('create a textarea field', (done) => {
wrapper = mount(Field, { wrapper = mount(Field, {
propsData: { propsData: {
type: 'textarea' type: 'textarea',
autosize: true
} }
}); });
setTimeout(() => { setTimeout(() => {
expect(wrapper.hasClass('van-field--min-height')).to.be.true; expect(wrapper.hasClass('van-field')).to.be.true;
done(); done();
}, 50); }, 50);
}); });