diff --git a/packages/core-data/src/components/FacetSlider.js b/packages/core-data/src/components/FacetSlider.js index 45b7fcce..5adc3f56 100644 --- a/packages/core-data/src/components/FacetSlider.js +++ b/packages/core-data/src/components/FacetSlider.js @@ -146,6 +146,9 @@ type Props = { */ onValueChange: (value: [number, number]) => void, + /** + * Callback fired when the range is done changing. + */ onValueCommit?: (value: [number, number]) => void, /** @@ -165,6 +168,8 @@ type Props = { }; const FacetSlider = (props: Props) => { + const { clearTimer, setTimer } = useTimer(); + /** * Callback fired when the left button is clicked. This function decrements the min range value by the "step" prop. * @@ -179,7 +184,13 @@ const FacetSlider = (props: Props) => { } props.onValueChange([newStart, end]); - }, [props.min, props.onValueChange, props.step, props.value]); + + // If provided, delay the onValueCommit function call + if (props.onValueCommit) { + clearTimer(); + setTimer(() => props.onValueCommit([newStart, end])); + } + }, [props.min, props.onValueChange, props.onValueCommit, props.step, props.value]); /** * Callback fired when the right button is clicked. This function increments the max range value by the "step" prop. @@ -195,7 +206,13 @@ const FacetSlider = (props: Props) => { } props.onValueChange([start, newEnd]); - }, [props.max, props.onValueChange, props.step, props.value]); + + // If provided, delay the onValueCommit function call + if (props.onValueCommit) { + clearTimer(); + setTimer(() => props.onValueCommit([start, newEnd])); + } + }, [props.max, props.onValueChange, props.onValueCommit, props.step, props.value]); return ( <> @@ -285,57 +302,6 @@ const FacetSlider = (props: Props) => { ))} )} - {/*{ props.zoom && (*/} - {/*