Select with more than 300 items doesn't reset on form reset unless `name` is set
Provide a general summary of the issue here
A Select with more than 300 items and no name does not restore its default selection on form reset. With 300 items or fewer, or with a name, it does.
Expected Behavior?
form.reset() restores defaultSelectedKey regardless of the collection size and whether name is set.
Current Behavior
Observed in headless Chromium (Playwright), react-aria-components 1.20.0 / react-aria 3.51.0, React 19.2.7. Each form holds one Select with defaultSelectedKey="k0"; the test picks "Item 1", then calls form.reset():
| items | name |
after reset |
|---|---|---|
| 300 | none | Item 0 ✅ |
| 301 | none | Item 1 ❌ |
| 300 | "x" |
Item 0 ✅ |
| 301 | "x" |
Item 0 ✅ |
Possible Solution
In react-aria/dist/private/select/HiddenSelect.mjs (3.51.0), useHiddenSelect registers the reset through useFormReset(props.selectRef, state.defaultValue, state.setValue). HiddenSelect passes selectRef: state.collection.size <= 300 ? selectRef : inputRef, but above 300 items the hidden <input> carrying inputRef is rendered only else if (name); otherwise it returns null. useFormReset then reads ref?.current?.form as undefined and never adds a reset listener.
Registering the listener independently of the rendered hidden input (e.g. from the trigger's form) would fix it.
Context
We found it while wiring form reset in a design system built on RAC. Related but different: #8034 (required validation above 300 items) and #3917 (missing value above 300 items).
️ Steps to Reproduce
import { Select, SelectValue, Button, Popover, ListBox, ListBoxItem } from "react-aria-components";
function Repro({ size, name }) {
const items = Array.from({ length: size }, (_, i) => ({ id: `k${i}`, name: `Item ${i}` }));
return (
<form>
<Select aria-label="Repro" defaultSelectedKey="k0" name={name}>
<Button><SelectValue /></Button>
<Popover>
<ListBox items={items}>{(it) => <ListBoxItem id={it.id}>{it.name}</ListBoxItem>}</ListBox>
</Popover>
</Select>
<button type="reset">Reset</button>
</form>
);
}
// <Repro size={301} />: pick "Item 1", press Reset → still "Item 1".
// <Repro size={300} /> or <Repro size={301} name="x" />: Reset → "Item 0".Version
react-aria-components 1.20.0, react-aria 3.51.0
What browsers are you seeing the problem on?
Chrome
If other, please specify.
No response
What operating system are you using?
macOS
Your Company/Team
No response
Tracking Issue
No response
Source: adobe/react-spectrum