Add first-class FormStore integration for Select and Combobox
Motivation
ComboboxSelect and related Ariakit widgets can own native controls for FormData, autofill, and native constraints. Nesting one inside Form does not connect its logical value to FormStore. Without an application bridge, the value is absent from FormStore schema input and submit callback values, and the visible widget does not receive Form field registration, touched state, errors, or invalid-field focus.
FormControl supplies the visible field behavior, but it deliberately does not supply value or onChange. The current Form with Select example therefore reads the Form value, writes widget changes back to the Form store, and wraps the visible trigger in FormControl.
The widget's native control has a different job. For example, ComboboxSelect owns a hidden native select, while a multiple-value Combobox can own repeated hidden inputs. These controls must remain transport details. Turning one into FormInput would compete with widget state, mishandle some array representations, and make an invisible element the target for field errors and focus.
This issue proposes a first-class, typed way to connect Ariakit widgets to FormStore without moving native transport ownership out of the widget.
Current widget-owned controls cover native FormData transport. This proposal covers FormStore values, schema and callback data, and visible Form field behavior.
Usage example
Applications currently write the bridge by hand:
type Values = { fruit: string };
function FruitField({ form }: { form: Ariakit.FormStore<Values> }) {
const name = form.names.fruit;
const value = Ariakit.useFormValue<string>(form, name);
return (
<Ariakit.ComboboxProvider
selectedValue={value}
setSelectedValue={(value) => form.setValue(name, value)}
>
<Ariakit.FormControl
store={form}
name={name}
render={<Ariakit.ComboboxSelect name={name.toString()} />}
/>
<Ariakit.ComboboxPopover>
<Ariakit.ComboboxItem value="Apple" />
<Ariakit.ComboboxItem value="Banana" />
</Ariakit.ComboboxPopover>
</Ariakit.ComboboxProvider>
);
}One possible component spelling would reduce that to:
<Ariakit.Form store={form}>
<Ariakit.ComboboxProvider>
<Ariakit.FormComboboxSelect name={form.names.fruit} />
<Ariakit.ComboboxPopover>
<Ariakit.ComboboxItem value="Apple" />
<Ariakit.ComboboxItem value="Banana" />
</Ariakit.ComboboxPopover>
</Ariakit.ComboboxProvider>
</Ariakit.Form>The component name and the choice between a dedicated component, a hook, and a reusable bridge remain open. The required behavior below is the proposed contract.
The result should give FormStore one current logical widget value, make schemas and submit callbacks receive it, target Form error and focus behavior at the visible control, and leave exactly the widget's existing native entry or entries in FormData.
Requirements
- Connect the widget's logical value to one typed
FormStorepath in both directions, with a clear value owner and no synchronization loop. - Register the visible widget control as the Form field so labels, descriptions, touched state, errors, validation, and invalid-field focus target the interactive element.
- Preserve each widget's existing native transport, autofill, and constraint behavior where applicable. Define adapter reset from the Form value owner without changing action-only widget behavior. Do not add a second successful control for the same logical value.
- Support scalar and array values, nested Form paths, disabled state,
required, externalform=, internal and explicit Form stores, schema input, and submit callback values. - Keep server-error clearing explicit: widget or FormStore value changes must not clear
serverErrors; application code clears the server-error source directly. - Define how controlled Form values and controlled widget values interact; the API must not silently introduce two independent value owners.
- Keep action-only widgets usable without a
FormStorebridge.
Non-goals
- Do not expose a widget's generated native control as
FormInputor as a separately registered field. - Do not make every raw native control inside
FormjoinFormStoreautomatically. - Do not infer Form schema input from
FormDataor add generalFormDataconversion helpers as part of this issue. - Do not change a widget's native value encoding only to fit the adapter.
Risks and test obligations
- Type tests should cover matching and mismatched scalar, array, and nested field paths.
- Runtime tests should cover updates in both directions, controlled and uncontrolled owners, reset, and prevention of duplicate writes.
- Form integration tests should verify touched and error state on the visible control, schema and submit callback input, invalid-field focus, and that widget changes retain server errors until application code explicitly clears the server-error source.
- Browser tests should verify exact
FormDataentries, autofill,required, disabled omission, externalform=, scalar and multiple values, and that no duplicate successful control is present. - Add widget-specific focus, popup, portal, server-rendering, and hydration coverage when the selected implementation changes those paths.
Workaround
Use useFormValue and form.setValue to control the widget from the Form store, then apply FormControl to the visible interactive element, as shown in the current example.
Possible implementations
- Add dedicated Form adapters for
ComboboxSelectand other widgets with different value contracts. - Add a typed value and visible-control bridge that widget-specific components can compose.
- Keep the current primitives and publish a standard adapter pattern. This is the smallest option, but it leaves repeated ownership and typing code in applications.
The implementation must keep the visible field and native transport roles separate. #6795 implemented repeated native controls for the case raised in #5058, and #6832 introduced ComboboxSelect for #6796. Those changes cover native transport, not FormStore integration. #6892 and #1861 show why disabled and reset ownership need explicit coverage.
Source: ariakit/ariakit