Add debounce to slider onChange; truncate slider labels to specified precision#68
Add debounce to slider onChange; truncate slider labels to specified precision#68
Conversation
marcus-kestler
left a comment
There was a problem hiding this comment.
You don't need to debounce the slider. It should be on mouseup which is already handled in SliderBar. Just emit a final event like "changeComplete" and use that to trigger the save.
this has nothing to do with saves, it was always intended to be debounced |
erik-nieh
left a comment
There was a problem hiding this comment.
Step value/truncating looks good
@marcus-kestler I think debouncing this change is abstractly useful for this component - it will probably improve the HA experience but is necessary for future features/work as well.
|
|
||
| expect(onChange).not.toHaveBeenCalled(); | ||
|
|
||
| jest.advanceTimersByTime(expectedDebounceTime); |
There was a problem hiding this comment.
This feature is great.
We had a very poor custom implementation related to stepper motor testing with pytest that always caused trouble in a previous job.
src/components/Slider/Slider.tsx
Outdated
| // debounce onChange events to prevent excessive updates when e.g. dragging the slider | ||
| const debouncedOnChange = useDebouncedCallback( | ||
| useCallback((value: number | number[]) => onChange?.(value), [onChange]), | ||
| 300 |
There was a problem hiding this comment.
Can we make this a prop? There might be some use cases in the future where a "live" slider is useful.
2350bfb to
96d6a44
Compare
Rationale
The slider component currently has two problems:
stepvalue, resulting in poor readability with high-precision valuesChanges
stepTesting
storybook
Screen.Recording.2026-02-06.at.5.35.45.PM.mov