@@ -151,11 +151,20 @@ export const BFormSpinbutton = /*#__PURE__*/ Vue.extend({
151
151
}
152
152
} ,
153
153
methods : {
154
- setValue ( value ) {
155
- if ( ! this . disabled ) {
154
+ stepValue ( direction ) {
155
+ // Sets a new incremented or decremented value, supporting optional wrapping
156
+ // Direction is either +1 or -1
157
+ let value = this . localValue
158
+ if ( ! this . disabled && ! isNull ( value ) ) {
159
+ const step = this . computedStep * direction
156
160
const min = this . computedMin
157
161
const max = this . computedMax
162
+ const mult = this . computedMult
158
163
const wrap = this . wrap
164
+ // We ensure that the value steps like a native input
165
+ value = Math . round ( ( value - min ) / step ) * step + min + step )
166
+ // We ensure that precision is maintained (decimals)
167
+ value = Math . round ( value * mult ) / mult
159
168
this . localValue =
160
169
value > max ? ( wrap ? min : max ) : value < min ? ( wrap ? max : min ) : value
161
170
}
@@ -172,21 +181,15 @@ export const BFormSpinbutton = /*#__PURE__*/ Vue.extend({
172
181
if ( isNull ( value ) ) {
173
182
this . localValue = this . computedMin
174
183
} else {
175
- const step = this . computedStep
176
- const mult = this . computedMult
177
- // We ensure that precision is maintained
178
- this . setValue ( Math . floor ( value * mult + step * mult ) / mult )
184
+ this . stepValue ( + 1 )
179
185
}
180
186
} ,
181
187
decrement ( ) {
182
188
const value = this . localValue
183
189
if ( isNull ( value ) ) {
184
190
this . localValue = this . wrap ? this . computedMax : this . computedMin
185
191
} else {
186
- const step = this . computedStep
187
- const mult = this . computedMult
188
- // We ensure that precision is maintained
189
- this . setValue ( Math . floor ( value * mult - step * mult ) / mult )
192
+ this . stepValue ( - 1 )
190
193
}
191
194
} ,
192
195
onKeydown ( evt ) {
0 commit comments