Permalink
Browse files

fix: follow input/change event behavior for native input element

  • Loading branch information...
ktsn committed Mar 6, 2018
1 parent 5a0bb62 commit f1b2b541c740b01904b166e23dbebbe418b56f4b
Showing with 13 additions and 7 deletions.
  1. +13 −7 src/RangeSlider.vue
View
@@ -47,7 +47,8 @@ export default {
data () {
return {
actualValue: null
actualValue: null,
dragStartValue: null
}
},
@@ -101,6 +102,7 @@ export default {
methods: {
dragStart (event: Event, offset: { left: number, top: number }) {
this.dragStartValue = this.actualValue
if (event.target === this.$refs.knob) {
return
}
@@ -111,20 +113,24 @@ export default {
drag (event: Event, offset: { left: number, top: number }) {
const { offsetWidth } = this.$refs.inner
this.actualValue = this.round(this.valueFromBounds(offset.left, offsetWidth))
this.emitEvent(this.actualValue)
this.emitInput(this.actualValue)
},
dragEnd (event: Event, offset: { left: number, top: number }) {
const { offsetWidth } = this.$refs.inner
this.actualValue = this.round(this.valueFromBounds(offset.left, offsetWidth))
this.emitEvent(this.actualValue, true)
if (this.dragStartValue !== this.actualValue) {
this.emitChange(this.actualValue)
}
},
emitEvent(value: number, isDragEnd: ?boolean) {
emitInput(value) {
this.$emit('input', value)
if (isDragEnd) {
this.$emit('change', value)
}
},
emitChange(value) {
this.$emit('change', value)
},
valueFromBounds (point: number, width: number) {

0 comments on commit f1b2b54

Please sign in to comment.