Date pickers
A date picker must submit a native field value while presenting a calendar UI.
Conform · Hook
useControl connects a custom React UI to a hidden native form control so Conform can observe values and browser-like events. It is intended for widgets such as date pickers, rich selects, and toggles.
useControl bridges a custom React component to a hidden native form control. Register the native element, use the control's current state to render the custom UI, call change when the UI value changes, and call blur when interaction leaves the logical control; focus can be delegated through the hook's callback.
const control = useControl(options);| Name | Type | Description |
|---|---|---|
options | UseControlOptions | An options object for configuring the control, including the field name and optional initial value; the hook also accepts configuration used to identify the form control. |
A control object that registers the native element and exposes synchronized state plus helpers such as register(), change(), blur(), and focus().
import { useControl } from '@conform-to/react/future';
export function Rating({ name }: { name: string }) {
const control = useControl({ name, initialValue: '0' });
return (
<div>
<input {...control.register()} type="hidden" />
{[1, 2, 3, 4, 5].map((rating) => (
<button
key={rating}
type="button"
aria-pressed={control.value === String(rating)}
onClick={() => control.change(String(rating))}
>
{rating}
</button>
))}
</div>
);
}Registers a hidden native control and synchronizes a custom rating UI by changing the control value.
A date picker must submit a native field value while presenting a calendar UI.
A library select needs Conform-compatible value and event synchronization.
A toggle or other custom widget needs to participate in native form handling.
useControl connects a custom UI to a hidden native form control. The native control remains the authoritative form value, while the custom component calls change and blur to emit corresponding form events.
Follow-up: Why register a native control instead of relying only on component state? The native control participates in browser form behavior and supplies the value that Conform observes.
Register a hidden input or another native control with control.register(). Render the custom component from control state, then call control.change(value) when the user selects a new value.
Follow-up: How should the native control type be chosen? Choose it according to the form data the submission must produce, not according to the custom widget's visual appearance.
control.blur() dispatches blur-related form events, but it does not move actual keyboard focus. For accessibility, use the hook's focus callback or native DOM focus methods to delegate focus to the visible custom element.
Follow-up: What additional care is needed for composite widgets? Ignore focus transitions between descendants and use the component library's close callback when appropriate.
useInputControluseFormBaseControlcontrol.registercontrol.changecontrol.blur