Skip to main content
Version: 2.0

RHFSlider

Sliders reflect a range of values along a bar, from which users may select a single value. They are ideal for adjusting settings such as volume or brightness. RHFSlider extends Slider and can be customized in a similar way.

Usage

import RHFSlider, { RHFSliderProps } from '@nish1896/rhf-mui-components/mui/slider';
<RHFSlider
fieldName="score"
register={register}
errorMessage={errors?.score?.message}
/>

Examples

API

RHFSliderProps extends SliderProps and accepts the following additional props:

NameTypeRequiredDescription
fieldNamestringReact Hook Form requires name as a key for the registration process. This is a required prop for all components.
controlUseFormControlThe control option yielded on calling the useForm hook.
registerOptionsRegisterOptionsRegister options for validation if using react-hook-form without any validation libraries like yup or Joi.
requiredbooleanIndicates that the field is mandatory by adding an asterisk symbol (*) to the formLabel. This visual cue helps users quickly identify required fields in the form.
onValueChange(value: number OR number[], activeThumb: number, event) => voidOptional callback function returning the selected value of RHFSlider.
labelReactNodeThe text to render in FormLabel component. By default, the value of fieldName such as firstName will be transformed to display "First Name".
showLabelAboveFormFieldbooleanRenders the form label above the field by default. Set this prop to false to hide the label.
formLabelPropsFormLabelPropsFormLabelProps to customise FormLabel component for a field. Multiple fields can be configured using the ConfigProvider component.
helperTextReactNodeThe content to display within the FormHelperText component below the field. If the field validation fails, this content will be overridden by the corresponding error message.
errorMessageReactNodeError message to be shown for a field in FormHelperText component.
hideErrorMessagebooleanA flag to prevent replacement of helper text of a field by the error message when the validation is triggered.
formHelperTextPropsFormHelperTextPropsFormHelperTextProps to customise FormHelperText component for a field. Multiple fields can be configured using the ConfigProvider component.