Improve NumberInput with dragging to change value and escape/right-click to abort (#1469)

* Improve NumberInput with dragging to change value and escape to abort

Closes #1468

* Fix slowing with Shift and integer mode
This commit is contained in:
Keavon Chambers
2023-11-21 17:26:28 -08:00
committed by GitHub
parent da4d95fa7b
commit 34c6c0431b
9 changed files with 488 additions and 151 deletions
+5 -5
View File
@@ -9,13 +9,13 @@ export function debouncer<T>(callFn: (value: T) => unknown, { debounceTime = 60
let currentValue: T | undefined;
let recentlyUpdated: boolean = false;
const emitValue = () => {
const debounceEmitValue = () => {
recentlyUpdated = false;
if (currentValue === undefined) return;
updateValue(currentValue);
debounceUpdateValue(currentValue);
};
const updateValue = (newValue: T) => {
const debounceUpdateValue = (newValue: T) => {
if (recentlyUpdated) {
currentValue = newValue;
return;
@@ -24,8 +24,8 @@ export function debouncer<T>(callFn: (value: T) => unknown, { debounceTime = 60
callFn(newValue);
recentlyUpdated = true;
currentValue = undefined;
setTimeout(emitValue, debounceTime);
setTimeout(debounceEmitValue, debounceTime);
};
return { updateValue };
return { debounceUpdateValue };
}