@piplup/rhf-adaptershtmlComponents
HtmlTextareaElement
Register a native textarea with react-hook-form using HtmlTextareaElement, with value handling, validation and error state.
HtmlTextareaElement connects a native <textarea> to React Hook Form while preserving the ergonomics of a regular textarea component.
Import
import { HtmlTextareaElement } from '@piplup/rhf-adapters/html';Usage
'use client';import { HtmlTextareaElement } from '@piplup/rhf-adapters/html';import { useForm } from 'react-hook-form';export default function Page() { const { control, handleSubmit } = useForm(); return ( <form onSubmit={handleSubmit((data) => { alert(JSON.stringify(data, null, 2)); })} noValidate > <HtmlTextareaElement className="border px-2 block rounded w-full" control={control} defaultValue="" name="description" placeholder="Enter a description" rows={4} /> <input className="bg-black hover:bg-black/90 px-4 py-1 text-white rounded mt-3" type="submit" value="Submit" /> </form> );}Props
Prop
Type
HtmlTextareaElement accepts textarea props together with adapter props such as control, rules, messages, and transform.
The
refis forwarded to the underlying<textarea>element.
useHtmlTextareaAdapter
useHtmlTextareaAdapter exposes the value, events, and field-state-aware props needed to build a custom textarea component on top of React Hook Form.
Import
import { useHtmlTextareaAdapter } from '@piplup/rhf-adapters/html';import * as React from 'react';import { useHtmlTextareaAdapter } from './adapter';import type { UseHtmlTextareaAdapterProps } from './adapter';import type { FieldPath, FieldValues } from 'react-hook-form';export interface HtmlTextareaElementProps< TTransformedValue extends number | readonly string[] | string | undefined, TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,> extends Omit<React.ComponentProps<'textarea'>, 'defaultValue' | 'name' | 'style' | 'type'>, Omit< UseHtmlTextareaAdapterProps<TTransformedValue, TFieldValues, TName>, 'composeClassName' | 'composeHelperText' | 'onBlur' | 'onChange' > {}function HtmlTextareaComponent< TTransformedValue extends number | readonly string[] | string | undefined, TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,>( props: HtmlTextareaElementProps<TTransformedValue, TFieldValues, TName>, ref: React.Ref<HTMLTextAreaElement>,): React.ReactElement { const { classes, className, control, defaultValue, disabled, disableOnError, disableOnIsSubmitting, error, errorParser, helperText, max, maxLength, messages, min, minLength, name, onBlur, onChange, pattern, required, rules, shouldUnregister, style, title, transform, ...rest } = props; const { error: _error, helperText: _helperText, ...adapter } = useHtmlTextareaAdapter( { classes, className, composeClassName: true, composeHelperText: false, control, defaultValue, disabled, disableOnError, disableOnIsSubmitting, error, errorParser, helperText, max, maxLength, messages, min, minLength, name, onBlur, onChange, pattern, required, rules, shouldUnregister, style, title, transform, }, ref, ); return <textarea {...rest} {...adapter} />;}export const HtmlTextareaElement = React.forwardRef(HtmlTextareaComponent);if (process.env.NODE_ENV !== 'production') { HtmlTextareaElement.displayName = 'HtmlTextareaElement';}Props
Prop
Type
Return value
Prop
Type
Notes
- Use this hook when a custom multiline input should still participate in React Hook Form validation and state management.
- The hook is built on top of
useControllerAdapter. - It is a textarea-specific variant of the HTML input adapter with checkbox- and type-specific props removed.
Notes
- Use this component when a field should behave like a regular textarea but still participate in React Hook Form validation and state.
- The component is built on top of
useHtmlTextareaAdapter.