Toolbar number input (#2288)

* Listen for ‘input’ event when input type is number, otherwise listen for 'change' event.

* Remove checks for options type in the event handlers.
This commit is contained in:
Pegah Sarram 2019-02-13 12:16:52 -08:00 committed by Deep Tailor
parent 21e08709cb
commit d0ab59f9da

View File

@ -7,8 +7,7 @@
<input :id="uid"
:type="options.type"
:value="options.value"
v-bind="options.attrs"
@change="onChange"/>
v-bind="options.attrs"/>
</div>
</template>
@ -31,15 +30,26 @@ export default {
uid: `mct-input-id-${inputUniqueId}`
};
},
mounted() {
if (this.options.type === 'number') {
this.$el.addEventListener('input', this.onInput);
} else {
this.$el.addEventListener('change', this.onChange);
}
},
beforeDestroy() {
if (this.options.type === 'number') {
this.$el.removeEventListener('input', this.onInput);
} else {
this.$el.removeEventListener('change', this.onChange);
}
},
methods: {
onChange(event) {
let value = event.target.value;
if (this.options.type === 'number') {
value = event.target.valueAsNumber;
}
this.$emit('change', value, this.options);
this.$emit('change', event.target.value, this.options);
},
onInput(event) {
this.$emit('change', event.target.valueAsNumber, this.options);
}
}
}