Skip to main content
Version: 2.0

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:

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: string, event: ChangeEvent) => voidAn optional callback function when the value of a field changes.
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.
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.