RHFTextField
Text fields are a core component of any form, allowing users to input text into the UI. The RHFTextField component extends the functionality of TextField, thus accepting almost all TextField props while providing additional customization options!
Usage
import RHFTextField, { RHFTextFieldProps } from '@nish1896/rhf-mui-components/mui/textfield';
To render a fully functional RHFTextField
, you only need 3-4 essential props.
<RHFTextField
fieldName="firstName"
control={control}
errorMessage={errors?.firstName?.message}
/>
Examples
API
The RHFTextFieldProps
interface extends TextFieldProps
and includes the following additional props:
Name | Type | Required | Description |
---|---|---|---|
fieldName | string | ✅ | React Hook Form requires name as a key for the registration process. This is a required prop for all components. |
control | UseFormControl | ✅ | The control option yielded on calling the useForm hook. |
registerOptions | RegisterOptions | Register options for validation if using react-hook-form without any validation libraries like yup or Joi. | |
onValueChange | (value: string, event: ChangeEvent) => void | An optional callback function when the value of a field changes. | |
showLabelAboveFormField | boolean | Render form label above the form field in FormLabel component. | |
formLabelProps | FormLabelProps | FormLabelProps to customise FormLabel component for a field. Multiple fields can be configured using the ConfigProvider component. | |
errorMessage | ReactNode | Error message to be shown for a field in FormHelperText component. | |
hideErrorMessage | boolean | A flag to prevent replacement of helper text of a field by the error message when the validation is triggered. | |
formHelperTextProps | FormHelperTextProps | FormHelperTextProps to customise FormHelperText component for a field. Multiple fields can be configured using the ConfigProvider component. |