Skip to main content
Version: v2

RHFNumberInputNEW

RHFNumberInput is an enhanced version of the TextField component which accepts only integer or float values. It retains the core functionality, styling options, and flexibility of the TextField, while seamlessly integrating with react-hook-form for number-specific input handling.

Usage

import RHFNumberInput, { RHFNumberInputProps } from '@nish1896/rhf-mui-components/mui/number-input';

To render a fully functional RHFNumberInput, you only need 3-4 essential props.

<RHFNumberInput
fieldName="age"
control={control}
errorMessage={errors?.age?.message}
/>

Examples

API

The RHFNumberInputProps interface extends TextFieldProps and includes 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.
onValueChange(value: number OR null) => voidAn optional callback function that returns the parsed numeric value, which can be an integer, float, or null if the input is empty.
labelReactNodeThe text to render in FormLabel component. By default, the value of fieldName such as firstName will be transformed to display "First Name" using the fieldNameToLabel function.
showLabelAboveFormFieldbooleanRender form label above the form field in FormLabel component.
formLabelPropsFormLabelPropsFormLabelProps to customise FormLabel component for a field. Multiple fields can be configured using the ConfigProvider component.
showMarkersbooleanShow the increment and decrement markers on number input. Hidden by default.
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.