Skip to content

Commit

Permalink
fix(slider): call onChangeEnd on blur after changing value
Browse files Browse the repository at this point in the history
  • Loading branch information
jer3m01 committed May 3, 2024
1 parent 0fe2ba0 commit c73be2c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/core/src/slider/create-slider-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ interface StateOpts {
}

export function createSliderState(props: StateOpts): SliderState {
let dirty = false;

const mergedProps: StateOpts = mergeDefaultProps(
{
minValue: () => 0,
Expand Down Expand Up @@ -239,10 +241,12 @@ export function createSliderState(props: StateOpts): SliderState {
};

const incrementThumb = (index: number, stepSize = 1) => {
dirty = true;
snapThumbValue(index, Math.max(stepSize, props.step!()));
};

const decrementThumb = (index: number, stepSize = 1) => {
dirty = true;
snapThumbValue(index, -Math.max(stepSize, props.step!()));
};

Expand All @@ -254,7 +258,13 @@ export function createSliderState(props: StateOpts): SliderState {
isThumbDragging: (index) => isDragging()[index],
setThumbDragging: updateDragging,
focusedThumb: focusedIndex,
setFocusedThumb: setFocusedIndex,
setFocusedThumb: (index: number | undefined) => {
if (index === undefined && dirty) {
dirty = false;
mergedProps.onChangeEnd?.(values());
}
setFocusedIndex(index);
},
getThumbPercent: (index) => getValuePercent(values()[index]),
getValuePercent,
getThumbValueLabel: (index) => getFormattedValue(values()[index]),
Expand Down

0 comments on commit c73be2c

Please sign in to comment.