Another thing, I don't know if that's intended, but when the slider is in disabled state, clicking on it invokes onChangeEnd.
While it's useful if you want it to behave like a checkbox, but the problem is that it runs the callback with a value from it's own internal state, which may not be what I want it to be after clicking on it.
Maybe i want to enable it and set a different value.
I can't use onClick because then dragging won't work.
Sure i could probably do some wrapper that holds the previous disabled boolean ref, and block the callback when disabled state changes, and set new value from props instead.
`
const TimeRangeSlider = ({ onChange, value, defaultValue, ...props }: TimeRangeSlider) => {
const previousValue = useRef(value || defaultValue);
const disabledRef = useRef(!previousValue.current);
useEffect(() => {
disabledRef.current = props.disabled || false;
}, [props.disabled]);
const handleChangeEnd = (time_window: [number, number]) => {
if (value && time_window[0] === value[0] && time_window[1] === value[1]) {
return;
}
if (disabledRef.current && defaultValue) {
previousValue.current = defaultValue;
onChange(defaultValue, true);
return;
}
const valueFix: VisitTimeWindow = [time_window[0], time_window[1]];
previousValue.current = valueFix;
onChange(valueFix, true);
};
`
well, maybe its my own niche case. Typically the slider should remember the last state before disable, freeze changes, and call onChange with last value when enabled, that makes more sense for typical use.
It is mostly my own condition where I want multiple sliders, 1 slider per day, and 1 slider as default for reference.
So when sliders for specific day enabled, it uses the default set by other slider, not that last internal state. So i made a wrapper that intercept the default behavior.