@piplup/rhf-adaptershtmlComponents
HtmlInputElement
Register native HTML inputs with react-hook-form: text, email, number, date, checkbox, radio, file, range and more, with validation wiring.
HtmlInputElement connects a native <input> to React Hook Form and supports common input types without manually wiring register, Controller, or field-state plumbing.
Import
import { HtmlInputElement } from '@piplup/rhf-adapters/html';Usage
Text
'use client';import { HtmlInputElement } from '@piplup/rhf-adapters/html';import { useForm } from 'react-hook-form';export default function Page() { const { control, handleSubmit } = useForm({ defaultValues: { input: '', }, }); return ( <form onSubmit={handleSubmit((data) => { alert(JSON.stringify(data, null, 2)); })} noValidate > <HtmlInputElement className="border px-2 block rounded" control={control} name="input" placeholder="Type text here" type="text" /> <input className="bg-black hover:bg-black/90 px-4 py-1 text-white rounded mt-3" type="submit" value="Submit" /> </form> );}Password
'use client';import { HtmlInputElement } from '@piplup/rhf-adapters/html';import { useForm } from 'react-hook-form';export default function Page() { const { control, handleSubmit } = useForm({ defaultValues: { 'secure-input': '', }, }); return ( <form onSubmit={handleSubmit((data) => { alert(JSON.stringify(data, null, 2)); })} noValidate > <HtmlInputElement control={control} name="secure-input" placeholder="Type your super secret password here" type="password" /> </form> );}Number
'use client';import { HtmlInputElement } from '@piplup/rhf-adapters/html';import { useForm } from 'react-hook-form';export default function Page() { const { control, handleSubmit } = useForm({ defaultValues: { randomNumber: 0, }, }); return ( <form onSubmit={handleSubmit((data) => { alert(JSON.stringify(data, null, 2)); })} noValidate > <HtmlInputElement control={control} name="randomNumber" placeholder="Type a random number here" type="number" /> </form> );}'use client';import { HtmlInputElement } from '@piplup/rhf-adapters/html';import { useForm } from 'react-hook-form';export default function Page() { const { control, handleSubmit } = useForm({ defaultValues: { myEmail: '', }, }); return ( <form onSubmit={handleSubmit((data) => { alert(JSON.stringify(data, null, 2)); })} noValidate > <HtmlInputElement control={control} name="myEmail" placeholder="Type your email here" type="email" /> </form> );}Radio
'use client';import { HtmlInputElement } from '@piplup/rhf-adapters/html';import { useForm } from 'react-hook-form';export default function Page() { const { control, handleSubmit } = useForm({ defaultValues: { option: '', }, }); return ( <form onSubmit={handleSubmit((data) => { alert(JSON.stringify(data, null, 2)); })} noValidate > <div> <HtmlInputElement control={control} id="one" name="option" type="radio" value="one" /> <label htmlFor="one">One</label> </div> <div> <HtmlInputElement control={control} id="two" name="option" type="radio" value="two" /> <label htmlFor="two">Two</label> </div> </form> );}Checkbox
'use client';import { HtmlInputElement } from '@piplup/rhf-adapters/html';import { useForm } from 'react-hook-form';export default function Page() { const { control, handleSubmit } = useForm({ defaultValues: { checkbox: [], }, }); return ( <form onSubmit={handleSubmit((data) => { alert(JSON.stringify(data, null, 2)); })} noValidate > <div> <HtmlInputElement control={control} id="one" name="checkbox" type="checkbox" value="one" /> <label htmlFor="one">One</label> </div> <div> <HtmlInputElement control={control} id="two" name="checkbox" type="checkbox" value="two" /> <label htmlFor="two">Two</label> </div> </form> );}Color
'use client';import { HtmlInputElement } from '@piplup/rhf-adapters/html';import { useForm } from 'react-hook-form';export default function Page() { const { control, handleSubmit } = useForm({ defaultValues: { color: '', }, }); return ( <form onSubmit={handleSubmit((data) => { alert(JSON.stringify(data, null, 2)); })} noValidate > <HtmlInputElement control={control} name="color" type="color" /> </form> );}Range
'use client';import { HtmlInputElement } from '@piplup/rhf-adapters/html';import { useForm } from 'react-hook-form';export default function Page() { const { control, handleSubmit } = useForm({ defaultValues: { altitude: '', }, }); return ( <form onSubmit={handleSubmit((data) => { alert(JSON.stringify(data, null, 2)); })} noValidate > <HtmlInputElement control={control} name="altitude" type="range" /> </form> );}Date
'use client';import { HtmlInputElement } from '@piplup/rhf-adapters/html';import { useForm } from 'react-hook-form';export default function Page() { const { control, handleSubmit } = useForm({ defaultValues: { date: '', }, }); return ( <form onSubmit={handleSubmit((data) => { alert(JSON.stringify(data, null, 2)); })} noValidate > <HtmlInputElement control={control} name="date" type="date" /> </form> );}Time
'use client';import { HtmlInputElement } from '@piplup/rhf-adapters/html';import { useForm } from 'react-hook-form';export default function Page() { const { control, handleSubmit } = useForm({ defaultValues: { time: '', }, }); return ( <form onSubmit={handleSubmit((data) => { alert(JSON.stringify(data, null, 2)); })} noValidate > <HtmlInputElement control={control} name="time" type="time" /> </form> );}Date Time Local
'use client';import { HtmlInputElement } from '@piplup/rhf-adapters/html';import { useForm } from 'react-hook-form';export default function Page() { const { control, handleSubmit } = useForm({ defaultValues: { datetimeLocal: '', }, }); return ( <form onSubmit={handleSubmit((data) => { alert(JSON.stringify(data, null, 2)); })} noValidate > <HtmlInputElement control={control} name="datetimeLocal" type="datetime-local" /> </form> );}Month
'use client';import { HtmlInputElement } from '@piplup/rhf-adapters/html';import { useForm } from 'react-hook-form';export default function Page() { const { control, handleSubmit } = useForm({ defaultValues: { birthMonth: '', }, }); return ( <form onSubmit={handleSubmit((data) => { alert(JSON.stringify(data, null, 2)); })} noValidate > <HtmlInputElement control={control} name="birthMonth" type="month" /> </form> );}Week
'use client';import { HtmlInputElement } from '@piplup/rhf-adapters/html';import { useForm } from 'react-hook-form';export default function Page() { const { control, handleSubmit } = useForm({ defaultValues: { myWeek: '', }, }); return ( <form onSubmit={handleSubmit((data) => { alert(JSON.stringify(data, null, 2)); })} noValidate > <HtmlInputElement control={control} name="myWeek" type="week" /> </form> );}File
'use client';import { HtmlInputElement } from '@piplup/rhf-adapters/html';import { useForm } from 'react-hook-form';export default function Page() { const { control, handleSubmit } = useForm({ defaultValues: { uploadFiles: [], }, }); return ( <form onSubmit={handleSubmit((data) => { alert(JSON.stringify(data, null, 2)); })} noValidate > <HtmlInputElement control={control} name="uploadFiles" type="file" multiple /> </form> );}Search
'use client';import { HtmlInputElement } from '@piplup/rhf-adapters/html';import { useForm } from 'react-hook-form';export default function Page() { const { control, handleSubmit } = useForm({ defaultValues: { query: '', }, }); return ( <form onSubmit={handleSubmit((data) => { alert(JSON.stringify(data, null, 2)); })} noValidate > <HtmlInputElement control={control} name="query" placeholder="Type text to search" type="search" /> </form> );}Tel
'use client';import { HtmlInputElement } from '@piplup/rhf-adapters/html';import { useForm } from 'react-hook-form';export default function Page() { const { control, handleSubmit } = useForm({ defaultValues: { phone: '', }, }); return ( <form onSubmit={handleSubmit((data) => { alert(JSON.stringify(data, null, 2)); })} noValidate > <HtmlInputElement control={control} name="phone" placeholder="Type your phone number" type="tel" /> </form> );}URL
'use client';import { HtmlInputElement } from '@piplup/rhf-adapters/html';import { useForm } from 'react-hook-form';export default function Page() { const { control, handleSubmit } = useForm({ defaultValues: { website: '', }, }); return ( <form onSubmit={handleSubmit((data) => { alert(JSON.stringify(data, null, 2)); })} noValidate > <HtmlInputElement control={control} name="website" placeholder="Type your website url" type="url" /> </form> );}Props
Prop
Type
HtmlInputElement accepts native input props together with adapter props such as control, rules, transform, and message overrides.
The
refis forwarded to the underlying<input>element.
useHtmlInputAdapter
useHtmlInputAdapter returns value, event handlers, and field-state-aware props for custom input components that should behave like React Hook Form-controlled fields.
Import
import { useHtmlInputAdapter } from '@piplup/rhf-adapters/html';import * as React from 'react';import { useHtmlInputAdapter } from './adapter';import type { UseHtmlInputAdapterProps } from './adapter';import type { FieldPath, FieldValues } from 'react-hook-form';export interface HtmlInputElementProps< TTransformedValue extends number | readonly string[] | string | undefined, TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,> extends Omit< React.ComponentProps<'input'>, | 'checked' | 'defaultChecked' | 'defaultValue' | 'indeterminate' | 'name' | 'pattern' | 'style' | 'value' >, Omit< UseHtmlInputAdapterProps<TTransformedValue, TFieldValues, TName>, | 'composeClassName' | 'composeHelperText' | 'helperText' | 'internalClasses' | 'onBlur' | 'onChange' | 'type' > {}function HtmlInputComponent< TTransformedValue extends number | readonly string[] | string | undefined, TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,>( props: HtmlInputElementProps<TTransformedValue, TFieldValues, TName>, ref?: React.Ref<HTMLInputElement>,): React.ReactElement { const { checked, classes, className, control, defaultValue, disabled, disableOnError, disableOnIsSubmitting, error, errorParser, indeterminate, max, maxLength, messages, min, minLength, name, onBlur, onChange, pattern, required, rules, shouldUnregister, style, title, transform, type, value, ...rest } = props; const { error: hasError, helperText: _helperText, ...adapter } = useHtmlInputAdapter( { checked, classes, className, composeClassName: true, composeHelperText: false, control, defaultValue, disabled, disableOnError, disableOnIsSubmitting, error, errorParser, helperText: undefined, indeterminate, max, maxLength, messages, min, minLength, name, onBlur, onChange, pattern, required, rules, shouldUnregister, style, title, transform, type, value, }, ref, ); return <input aria-invalid={hasError} {...rest} {...adapter} />;}export const HtmlInputElement = React.forwardRef( HtmlInputComponent,) as typeof HtmlInputComponent & { displayName?: string;};if (process.env.NODE_ENV !== 'production') { HtmlInputElement.displayName = 'HtmlInputElement';}Props
Prop
Type
Return value
Prop
Type
Notes
- Use this hook for bespoke input components that still need React Hook Form registration and value synchronization.
- The hook is built on top of
useControllerAdapter. transform,checked, andindeterminateare useful when DOM values do not match your stored form value exactly.
Notes
- Use
transformwhen the field value shape differs from the DOM value. - Checkbox, radio, file, and other specialized input types can still reuse the same adapter surface.