Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Esvalirion committed Jan 27, 2021
1 parent c5c1037 commit ae760a5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/qComponents/QInputNumber/QInputNumber.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Component from './src/QInputNumber.vue';
import Component from './src/QInputNumber';

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ exports[`QInputNumber should match snapshot 1`] = `
label=""
suffixicon=""
tabindex=""
type="text"
validateevent="true"
type="number"
value=""
/>
Expand All @@ -45,8 +44,7 @@ exports[`QInputNumber should match snapshot without controls 1`] = `
label=""
suffixicon=""
tabindex=""
type="text"
validateevent="true"
type="number"
value=""
/>
Expand Down
29 changes: 17 additions & 12 deletions src/qComponents/QInputNumber/src/QInputNumber.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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')"
Expand Down Expand Up @@ -101,6 +103,10 @@ export default {
return false;
}
},
validateEvent: {
type: Boolean,
default: true
}
},
Expand Down Expand Up @@ -172,25 +178,21 @@ export default {
handleBlur(event) {
this.$emit('blur', event);
if (this.validateEvent) this.qFormItem?.validateField('blur');
},
handleFocus(event) {
this.$emit('focus', event);
},
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) {
Expand All @@ -204,7 +206,7 @@ export default {
this.prevNumber = userValue;
if (type === 'change') {
this.changesEmmiter(userValue);
this.changesEmmiter(userValue, type);
return;
}
Expand All @@ -219,9 +221,12 @@ export default {
passedData = this.number;
}
this.prevNumber = passedData;
if (type === 'change') {
this.$emit('input', passedData);
this.$emit('change', passedData);
if (this.validateEvent) this.qFormItem?.validateField('change');
return;
}
Expand Down
4 changes: 2 additions & 2 deletions stories/components/QInputNumber.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const Default = (_, { argTypes }) => ({
};
},
methods: {
handleEmit($event, type) {
console.log($event, type);
handleEmit(value, type) {
console.log(value, type);
}
},
template: `
Expand Down

0 comments on commit ae760a5

Please sign in to comment.