fix(RAC): relax inputRef type on Checkbox, Switch, and Radio to accept callback refs - #10451
Open
timges wants to merge 2 commits into
Open
fix(RAC): relax inputRef type on Checkbox, Switch, and Radio to accept callback refs#10451timges wants to merge 2 commits into
timges wants to merge 2 commits into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #10319
✅ Pull Request Checklist:
📝 Test Instructions:
CheckboxProps/CheckboxFieldProps,SwitchProps/SwitchFieldProps, andRadioProps/RadioFieldPropsall typedinputRefasRefObject<HTMLInputElement | null>, which meant a ref callback could not be passed even thoughmergeRefsalready accepts one and forwards it down to the underlying<input>.This PR:
inputRefon all six prop interfaces fromRefObject<HTMLInputElement | null>toRef<HTMLInputElement | null>.useCheckboxAriahelper'suserProvidedInputRefparameter to match (its return type, the already-merged/normalized ref, staysRefObjectsince that's what the underlyinguseCheckbox/useCheckboxGroupItemhooks require).Switch/SwitchFieldbuilt the merged ref inline on every render instead of memoizing it likeCheckbox/Radiodo, so a callback ref would be torn down and re-invoked on every re-render rather than only on mount/unmount. Wrapped it inuseMemoto match.Added a "should support callback ref" test to
Checkbox.test.js,Switch.test.js, andRadioGroup.test.jsfor 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:
🧢 Your Project:
Spectrum Metrics