[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.
This commit is contained in:
Carlos Roca
2024-12-24 08:13:45 +01:00
parent 271ad52cd4
commit 826e28754a

View File

@@ -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) {