diff --git a/packages/react/src/slider/root/SliderRoot.tsx b/packages/react/src/slider/root/SliderRoot.tsx index 99fbc92e14..6c3cfa2053 100644 --- a/packages/react/src/slider/root/SliderRoot.tsx +++ b/packages/react/src/slider/root/SliderRoot.tsx @@ -18,8 +18,8 @@ import { useFieldRootContext } from '../../field/root/FieldRootContext'; * * Documentation: [Base UI Slider](https://base-ui.com/react/components/slider) */ -const SliderRoot = React.forwardRef(function SliderRoot( - props: SliderRoot.Props, +const SliderRoot = React.forwardRef(function SliderRoot( + props: SliderRoot.Props, forwardedRef: React.ForwardedRef, ) { const { @@ -59,8 +59,9 @@ const SliderRoot = React.forwardRef(function SliderRoot( min, minStepsBetweenValues, name: nameProp ?? '', - onValueChange: onValueChangeProp ?? NOOP, - onValueCommitted: onValueCommittedProp ?? NOOP, + onValueChange: (onValueChangeProp as useSliderRoot.Parameters['onValueChange']) ?? NOOP, + onValueCommitted: + (onValueCommittedProp as useSliderRoot.Parameters['onValueCommitted']) ?? NOOP, orientation, rootRef: forwardedRef, step, @@ -118,7 +119,14 @@ const SliderRoot = React.forwardRef(function SliderRoot( {renderElement()} ); -}); +}) as { + ( + props: SliderRoot.Props & { + ref?: React.RefObject; + }, + ): React.JSX.Element; + propTypes?: any; +}; export namespace SliderRoot { export interface State extends FieldRoot.State { @@ -157,7 +165,7 @@ export namespace SliderRoot { values: readonly number[]; } - export interface Props + export interface Props extends Partial< Pick< useSliderRoot.Parameters, @@ -166,8 +174,6 @@ export namespace SliderRoot { | 'min' | 'minStepsBetweenValues' | 'name' - | 'onValueChange' - | 'onValueCommitted' | 'orientation' | 'largeStep' | 'step' @@ -179,7 +185,7 @@ export namespace SliderRoot { * * To render a controlled slider, use the `value` prop instead. */ - defaultValue?: number | readonly number[]; + defaultValue?: Value; /** * Whether the component should ignore user interaction. * @default false @@ -197,10 +203,26 @@ export namespace SliderRoot { * The value of the slider. * For ranged sliders, provide an array with two values. */ - value?: number | readonly number[]; + value?: Value; + /** + * Callback function that is fired when the slider's value changed. + * + * @param {number | number[]} value The new value. + * @param {Event} event The corresponding event that initiated the change. + * You can pull out the new value by accessing `event.target.value` (any). + * @param {number} activeThumbIndex Index of the currently moved thumb. + */ + onValueChange?: (value: Value, event: Event, activeThumbIndex: number) => void; + /** + * Callback function that is fired when the `pointerup` is triggered. + * + * @param {number | number[]} value The new value. + * @param {Event} event The corresponding event that initiated the change. + * **Warning**: This is a generic event not a change event. + */ + onValueCommitted?: (value: Value, event: Event) => void; } } - export { SliderRoot }; SliderRoot.propTypes /* remove-proptypes */ = { @@ -288,7 +310,7 @@ SliderRoot.propTypes /* remove-proptypes */ = { /** * Callback function that is fired when the slider's value changed. * - * @param {number | readonly number[]} value The new value. + * @param {number | number[]} value The new value. * @param {Event} event The corresponding event that initiated the change. * You can pull out the new value by accessing `event.target.value` (any). * @param {number} activeThumbIndex Index of the currently moved thumb.