Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing of inputRef to RAC Checkbox/Switch #5967

Merged
merged 10 commits into from
Mar 6, 2024
Merged

Conversation

yihuiliao
Copy link
Member

Opening to start a discussion about how we would like to handle inputRef since we ran into some issues with 🌈 Checkbox/Switch.

In RAC, inputRef is constructed within the component so that in our 🌈 implementation of Checkbox/Switch we have no way of passing an inputRef down to the input. We can't use Context because Checkbox/Switch don't use our <Input> component.

If this is something we want, I can make adjustments to the ref support PR in 🌈 .

βœ… 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:

🧒 Your Project:

@yihuiliao yihuiliao changed the title Allow passing of inputRef for RAC Checkbox/Switch Allow passing of inputRef to RAC Checkbox/Switch Feb 28, 2024
@rspbot
Copy link

rspbot commented Feb 28, 2024

@yihuiliao yihuiliao marked this pull request as ready for review February 29, 2024 01:13
@rspbot
Copy link

rspbot commented Feb 29, 2024


/**
* Merges multiple refs into one. Works with either callback or object refs.
*/
export function mergeRefs<T>(...refs: ForwardedRef<T>[]): ForwardedRef<T> {
export function mergeRefs<T>(...refs: Array<ForwardedRef<T> | MutableRefObject<T>>): ForwardedRef<T> {
Copy link
Member Author

Choose a reason for hiding this comment

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

had to update the typing for this but not super sure about this change

Copy link
Member

Choose a reason for hiding this comment

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

react-aria/utils is in TS strict, so we're pretty well protected here
that said, I think it's the right change

packages/react-aria-components/src/Switch.tsx Outdated Show resolved Hide resolved

/**
* Merges multiple refs into one. Works with either callback or object refs.
*/
export function mergeRefs<T>(...refs: ForwardedRef<T>[]): ForwardedRef<T> {
export function mergeRefs<T>(...refs: Array<ForwardedRef<T> | MutableRefObject<T>>): ForwardedRef<T> {
Copy link
Member

Choose a reason for hiding this comment

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

react-aria/utils is in TS strict, so we're pretty well protected here
that said, I think it's the right change

@rspbot
Copy link

rspbot commented Mar 1, 2024

@rspbot
Copy link

rspbot commented Mar 1, 2024

Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

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

Just small code nit, but otherwise this looks fine to me. Thanks for coming up with the update!

packages/react-aria-components/src/Checkbox.tsx Outdated Show resolved Hide resolved
packages/react-aria-components/src/Switch.tsx Outdated Show resolved Hide resolved
@rspbot
Copy link

rspbot commented Mar 5, 2024

@rspbot
Copy link

rspbot commented Mar 6, 2024

@rspbot
Copy link

rspbot commented Mar 6, 2024

@rspbot
Copy link

rspbot commented Mar 6, 2024

## API Changes

unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any', access: 'private' }
unknown top level export { type: 'any', access: 'private' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'identifier', name: 'Column' }
unknown top level export { type: 'identifier', name: 'Column' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }

@react-aria/utils

mergeRefs

 mergeRefs<T> {
-  refs: Array<ForwardedRef<T>>
+  refs: Array<ForwardedRef<T> | MutableRefObject<T>>
   returnVal: undefined
 }

@yihuiliao yihuiliao merged commit a8ec966 into main Mar 6, 2024
27 checks passed
@yihuiliao yihuiliao deleted the rainbow-ref-support branch March 6, 2024 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants