Integrate a custom input
A select, combobox, date picker, or other custom widget needs to submit through a Conform form.
Conform · Hook
useInputControl connects custom or controlled inputs to Conform. It exposes the current value plus helpers that simulate input, change, focus, and blur events.
useInputControl accepts field metadata or equivalent options and returns a controller for integrating a custom input with Conform. Read its value for controlled rendering, call change to update the value and emit input/change events, and use focus or blur to simulate the corresponding browser events.
useInputControl(metaOrOptions)| Name | Type | Description |
|---|---|---|
metaOrOptions | FieldMetadata | { key: string; name: string; formId?: string; initialValue?: string } | Field metadata, or an options object containing key, name, formId, and initialValue. |
An input control object exposing value, change(value: string), blur(), and focus() helpers.
import { useForm, useInputControl } from '@conform-to/react';
export function ColorField() {
const [form, fields] = useForm();
const color = useInputControl(fields.color);
return (
<select
name={fields.color.name}
value={color.value ?? ''}
onChange={(event) => color.change(event.target.value)}
onFocus={color.focus}
onBlur={color.blur}
>
<option value="">Choose a color</option>
<option value="red">Red</option>
</select>
);
}This connects a custom or controlled input to Conform by exposing its current value and browser-event helpers.
A select, combobox, date picker, or other custom widget needs to submit through a Conform form.
A controlled component must stay synchronized with Conform's field value.
A custom widget needs validation-related input and focus events emitted programmatically.
The hook accepts field metadata or an options object containing key, name, formId, and initialValue. It returns an input-control object with the current value and event helpers for a custom input.
Follow-up: What does change do beyond updating React state? It updates the value and simulates both the input and change browser events.
Use control.value as the controlled component's value, control.change when the component reports a new value, and control.focus and control.blur for corresponding simulated events. This lets the custom component participate in Conform's form behavior.
Follow-up: How would you provide real focus? Forward the focus event and call the target element's native focus method.
focus simulates focus and focusin, while blur simulates blur and focusout. Neither operation changes the browser's actual keyboard focus.
Follow-up: Why might invalid-field focusing need extra work? A custom input may not be the element Conform can focus, so its focus handler should delegate to the desired element.
useFormField metadatacontrol.valuecontrol.changecontrol.focuscontrol.blur