Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix oh-stepper sends command on Item state update due to rounding #2096

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -51,7 +52,20 @@ export default {
// do NOT convert to number, instead return string, otherwise formatting wouldn't work
return parseFloat(value).toFixed(nbDecimals ? nbDecimals.length : 0)
},
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 = (num) => (!isNaN(this.config.offset)) ? Number(this.toStepFixed(num - Number(this.config.offset))) : num
let newValue = applyOffset(Number(this.toStepFixed(value)))
if (isNaN(newValue)) newValue = this.config.min || this.config.max || 0
Expand Down