Skip to content

Commit

Permalink
Fix oh-stepper sends commands on Item state update due to rounding
Browse files Browse the repository at this point in the history
Fixes #1186.

Signed-off-by: Florian Hotze <[email protected]>
  • Loading branch information
florian-h05 committed Oct 4, 2023
1 parent 0449622 commit 0a651ac
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<f7-stepper ref="stepper" v-bind="config" :value="value" @stepper:change="onChange" @click.native.stop
:input="config.enableInput === true" :manual-input-mode="false" :format-value="formatValue" />
<f7-stepper ref="stepper" v-bind="config" @stepper:plusclick="onPlusMinusClick" @stepper:minusclick="onPlusMinusClick" @input="onInput"
:input="config.enableInput === true" :manual-input-mode="true" :format-value="formatValue" />
</template>

<style lang="stylus">
Expand All @@ -18,6 +18,7 @@ export default {
widget: OhStepperDefinition,
mounted () {
delete this.config.value
this.$refs.stepper.setValue(this.value)
},
computed: {
value () {
Expand Down Expand Up @@ -50,7 +51,20 @@ export default {
const nbDecimals = Number(this.config.step).toString().replace(',', '.').split('.')[1]
return parseFloat(Number(value)).toFixed(nbDecimals.length)
},
onChange (value) {
onPlusMinusClick () {
setTimeout(() => {
this.sendCommand(this.$refs.stepper.getValue())
}, 10)
},
onInput () {
if (!this.config.enableInput) return
setTimeout(() => {
const newValue = this.$refs.stepper.getValue()
if (Math.abs(newValue - this.value) < (this.config.step || 1)) return
this.sendCommand(newValue)
}, 1500)
},
sendCommand (value) {
const applyOffset = (value) => (typeof this.config.offset === 'number') ? Number(this.toStepFixed(value - this.config.offset)) : value
let newValue = applyOffset(Number(this.toStepFixed(value)))
if (newValue === this.value) return
Expand Down

0 comments on commit 0a651ac

Please sign in to comment.