Skip to content

fix(RAC): relax inputRef type on Checkbox, Switch, and Radio to accept callback refs - #10451

Merged
snowystinger merged 2 commits into
adobe:mainfrom
timges:relax-checkbox-switch-radio-inputref-type
Aug 12, 2026
Merged

fix(RAC): relax inputRef type on Checkbox, Switch, and Radio to accept callback refs#10451
snowystinger merged 2 commits into
adobe:mainfrom
timges:relax-checkbox-switch-radio-inputref-type

Conversation

@timges

@timges timges commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Closes #10319

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

CheckboxProps/CheckboxFieldProps, SwitchProps/SwitchFieldProps, and RadioProps/RadioFieldProps all typed inputRef as RefObject<HTMLInputElement | null>, which meant a ref callback could not be passed even though mergeRefs already accepts one and forwards it down to the underlying <input>.

This PR:

  • Widens inputRef on all six prop interfaces from RefObject<HTMLInputElement | null> to Ref<HTMLInputElement | null>.
  • Widens the internal useCheckboxAria helper's userProvidedInputRef parameter to match (its return type, the already-merged/normalized ref, stays RefObject since that's what the underlying useCheckbox/useCheckboxGroupItem hooks require).
  • Fixes a latent bug found while testing this: Switch/SwitchField built the merged ref inline on every render instead of memoizing it like Checkbox/Radio do, so a callback ref would be torn down and re-invoked on every re-render rather than only on mount/unmount. Wrapped it in useMemo to match.

Added a "should support callback ref" test to Checkbox.test.js, Switch.test.js, and RadioGroup.test.js for both the deprecated and Field variants, asserting the callback is invoked with the input node on mount and its cleanup function is called exactly once on unmount.

Run:

yarn jest packages/react-aria-components/test/Checkbox.test.js packages/react-aria-components/test/Switch.test.js packages/react-aria-components/test/RadioGroup.test.js
yarn check-types

🧢 Your Project:

Spectrum Metrics

…lback refs

CheckboxProps, SwitchProps, and RadioProps (and their Field variants) typed
inputRef as RefObject, so a ref callback couldn't be passed even though
mergeRefs already supports one. Widen inputRef to Ref on all six, widen
useCheckboxAria's internal parameter to match, and memoize Switch's ref
merge like Checkbox/Radio already do so a callback ref only tears down on
unmount instead of every render.

Closes adobe#10319
@timges timges changed the title Relax inputRef type on Checkbox, Switch, and Radio to accept callback refs fix(RAC): relax inputRef type on Checkbox, Switch, and Radio to accept callback refs Aug 11, 2026

@reidbarber reidbarber left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@snowystinger
snowystinger added this pull request to the merge queue Aug 12, 2026
Merged via the queue into adobe:main with commit d841ef5 Aug 12, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Relax type of CheckboxFieldProps["inputRef"] from RefObject to Ref

3 participants