diff --git a/src/qComponents/QInputNumber/QInputNumber.test.js b/src/qComponents/QInputNumber/QInputNumber.test.js index 623a1f98..fbbb5cd4 100644 --- a/src/qComponents/QInputNumber/QInputNumber.test.js +++ b/src/qComponents/QInputNumber/QInputNumber.test.js @@ -1,13 +1,13 @@ import Component from './src/QInputNumber.vue'; describe('QInputNumber', () => { - it('should match snapshot', async () => { + it('should match snapshot', () => { const { element } = shallowMount(Component); expect(element).toMatchSnapshot(); }); - it('should match snapshot without controls', async () => { + it('should match snapshot without controls', () => { const { element } = shallowMount(Component, { propsData: { controls: false diff --git a/src/qComponents/QInputNumber/__snapshots__/QInputNumber.test.js.snap b/src/qComponents/QInputNumber/__snapshots__/QInputNumber.test.js.snap index 71d533f3..82635c2c 100644 --- a/src/qComponents/QInputNumber/__snapshots__/QInputNumber.test.js.snap +++ b/src/qComponents/QInputNumber/__snapshots__/QInputNumber.test.js.snap @@ -22,8 +22,7 @@ exports[`QInputNumber should match snapshot 1`] = ` label="" suffixicon="" tabindex="" - type="text" - validateevent="true" + type="number" value="" /> @@ -45,8 +44,7 @@ exports[`QInputNumber should match snapshot without controls 1`] = ` label="" suffixicon="" tabindex="" - type="text" - validateevent="true" + type="number" value="" /> diff --git a/src/qComponents/QInputNumber/src/QInputNumber.vue b/src/qComponents/QInputNumber/src/QInputNumber.vue index 1c0a3b7b..d3705a7a 100644 --- a/src/qComponents/QInputNumber/src/QInputNumber.vue +++ b/src/qComponents/QInputNumber/src/QInputNumber.vue @@ -16,6 +16,8 @@ class="q-input-number__input" :disabled="isDisabled" :placeholder="placeholder" + :validate-event="false" + type="number" @blur="handleBlur" @focus="handleFocus" @input="handleChangeInput($event, 'input')" @@ -101,6 +103,10 @@ export default { return false; } + }, + validateEvent: { + type: Boolean, + default: true } }, @@ -179,18 +185,13 @@ export default { }, handleChangeInput(value, type) { - switch (value) { - case '-': - this.userNumber = type === 'change' ? this.prevNumber : value; - break; - case '': - this.userNumber = value; - this.changesEmmiter(null, type); - break; - default: - this.processUserValue(value, type); - break; + if (!value) { + this.userNumber = value; + this.changesEmmiter(null, type); + return; } + + this.processUserValue(value, type); }, processUserValue(value, type) { @@ -204,7 +205,7 @@ export default { this.prevNumber = userValue; if (type === 'change') { - this.changesEmmiter(userValue); + this.changesEmmiter(userValue, type); return; } @@ -219,6 +220,9 @@ export default { passedData = this.number; } + this.prevNumber = passedData; + if (this.validateEvent) this.qFormItem?.validateField('change'); + if (type === 'change') { this.$emit('input', passedData); this.$emit('change', passedData); diff --git a/stories/components/QInputNumber.stories.js b/stories/components/QInputNumber.stories.js index 333ae1e6..1d522307 100644 --- a/stories/components/QInputNumber.stories.js +++ b/stories/components/QInputNumber.stories.js @@ -20,8 +20,8 @@ export const Default = (_, { argTypes }) => ({ }; }, methods: { - handleEmit($event, type) { - console.log($event, type); + handleEmit(value, type) { + console.log(value, type); } }, template: `