Skip to main content

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';

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

<RHFTextField
fieldName="firstName"
register={register}
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.
registerUseFormRegisterThe register option yielded on calling the useForm hook.
registerOptionsRegisterOptionsRegister options if using react-hook-form without any validation libraries like yup or Joi.
onValueChange(e: ChangeEvent) => voidAn optional callback function when the value of a field changes. The changed value can be obtained from e.target.value.
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.
hideErrorMessagebooleanPrevent replacing of form HelperText by error message during validation trigger.
formHelperTextPropsFormHelperTextPropsFormHelperTextProps to customise FormHelperText component for a field. Multiple fields can be configured using the ConfigProvider component.