From 826e28754a0718a2323127935732ad53103abf8a Mon Sep 17 00:00:00 2001 From: Carlos Roca Date: Tue, 24 Dec 2024 08:13:45 +0100 Subject: [PATCH] [IMP] web_widget_numeric_step: throttle update calls when scrolling on field Before this changes, when scrolling on a field, the price update was collapsed because lots of calls to the function was made in a few seconds. With this changes, the field update, when using the scroll is limited to 1 each 0,1 seconds and the info is updated correctly. --- .../static/src/numeric_step.esm.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/web_widget_numeric_step/static/src/numeric_step.esm.js b/web_widget_numeric_step/static/src/numeric_step.esm.js index 94ef3b48c..18e66db0e 100644 --- a/web_widget_numeric_step/static/src/numeric_step.esm.js +++ b/web_widget_numeric_step/static/src/numeric_step.esm.js @@ -22,10 +22,19 @@ export class NumericStep extends FloatField { } _onWheel(ev) { ev.preventDefault(); - if (ev.deltaY > 0) { - this._doStep("minus"); - } else { - this._doStep("plus"); + if (!this._lastWheelTime) { + this._lastWheelTime = 0; + } + const now = Date.now(); + const throttleLimit = 100; + if (now - this._lastWheelTime >= throttleLimit) { + this._lastWheelTime = now; + + if (ev.deltaY > 0) { + this._doStep("minus"); + } else { + this._doStep("plus"); + } } } updateField(val) {