Skip to content

Commit d10ff14

Browse files
committed
UIEXT-2930: Ensure step size is always non-zero
UIEXT-2930 (Add configurable step size to NumberInputWidget)
1 parent 2680e7c commit d10ff14

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/components/src/components/forms/NumberInput/NumberInput.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,18 +201,26 @@ export default {
201201
* can be found. It prevents users from further invalidating the value in the input
202202
* by moving in the wrong direction (lower than min/higher than max).
203203
*
204-
* @param {Number} increment - the amount by which to change the current value.
204+
* It will snap to the nearest multiple of the given increment, i.e. initial
205+
* value 13 incremented by 10 will yield 20.
206+
*
207+
* @param {Number} increment - the amount by which to change the current
208+
* value. If value is 0, no update is performed.
205209
* @returns {undefined}
206210
*/
207211
changeValue(increment: number) {
212+
if (increment === 0) {
213+
return;
214+
}
215+
208216
let value = this.getParsedValue();
209217
if (!this.validate(value).isValid) {
210218
value = this.findNearestValidValue(value);
211219
}
212220
213221
/** Mimic stepping to nearest step with safe value rounding */
214222
let parsedVal = value + increment;
215-
let scaleFactor = 1 / Math.abs(increment); // eslint-disable-line no-magic-numbers
223+
let scaleFactor = 1 / Math.abs(increment);
216224
if (Math.abs(increment) < 1) {
217225
// Avoid rounding errors induced by fractional increments
218226
scaleFactor = Math.round(scaleFactor);

0 commit comments

Comments
 (0)