Skip to content

Add debounce to slider onChange; truncate slider labels to specified precision#68

Merged
tom-vx51 merged 6 commits intodevelopfrom
chore/slider-improvements
Feb 10, 2026
Merged

Add debounce to slider onChange; truncate slider labels to specified precision#68
tom-vx51 merged 6 commits intodevelopfrom
chore/slider-improvements

Conversation

@tom-vx51
Copy link
Collaborator

@tom-vx51 tom-vx51 commented Feb 7, 2026

Rationale

The slider component currently has two problems:

  • onChange events are fired for every change, which is very noisy when e.g. dragging a slider knob
  • Labels are not truncated to the specified step value, resulting in poor readability with high-precision values

Changes

  • Debounce onChange events
  • Truncate slider labels to specified step

Testing

storybook

Screen.Recording.2026-02-06.at.5.35.45.PM.mov

@tom-vx51 tom-vx51 requested a review from a team as a code owner February 7, 2026 01:37
Copy link

@marcus-kestler marcus-kestler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@tom-vx51
Copy link
Collaborator Author

tom-vx51 commented Feb 9, 2026

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

Copy link
Contributor

@erik-nieh erik-nieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

// debounce onChange events to prevent excessive updates when e.g. dragging the slider
const debouncedOnChange = useDebouncedCallback(
useCallback((value: number | number[]) => onChange?.(value), [onChange]),
300
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this a prop? There might be some use cases in the future where a "live" slider is useful.

@tom-vx51 tom-vx51 force-pushed the chore/slider-improvements branch from 2350bfb to 96d6a44 Compare February 10, 2026 18:35
@marcus-kestler marcus-kestler self-requested a review February 10, 2026 18:48
@tom-vx51 tom-vx51 merged commit 8189278 into develop Feb 10, 2026
1 check passed
@tom-vx51 tom-vx51 deleted the chore/slider-improvements branch February 10, 2026 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants