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

Checkbox: Add forward ref (BREAKING CHANGE) #1057

Merged
merged 4 commits into from Jul 17, 2020

Conversation

AlbertCarreras
Copy link
Contributor

@AlbertCarreras AlbertCarreras commented Jul 16, 2020

  • Adds ref forwarding to Checkbox
  • Added ref example to Docs
  • Added test for ref

Why?

We have use cases in the Pinterest codebase where we set a ref on a wrapping container for Checkbox in order to anchor other components on it.

To abstract this implementation, let's add a way for them to get it in a dryer way.

Moreover, without forwardedRefs, refs are set on the component's instance, not the actual input. So in each of those cases, people drill down to get the .

That is pretty hacky, so let's add a way for them to get it in a cleaner way.

Why is this a breaking change?

https://reactjs.org/docs/forwarding-refs.html#note-for-component-library-maintainers

When you start using forwardRef in a component library, you should treat it as a breaking change and release a new major version of your library. This is because your library likely has an observably different behavior (such as what refs get assigned to, and what types are exported), and this can break apps and other libraries that depend on the old behavior.

Can I get more documentation around this feature?

https://reactjs.org/docs/forwarding-refs.html#forwarding-refs-to-dom-components

Test Plan

  • Is it tested? YES
    * Is it accessible?
  • Is it documented? YES
    * Have you involved other stakeholders (such as a Pinterest Designer)?
Browser validating the click target is still correct validating layout looks good it's accessible (you can hit space to toggle the checkbox) Demo
Chrome CORRECT CORRECT CORRECT Kapture 2020-07-17 at 11 22 34
Safari CORRECT CORRECT FAILS unrelated to this change Kapture 2020-07-17 at 11 25 12
IE11 CORRECT CORRECT CORRECT Kapture 2020-07-17 at 11 21 04

@netlify
Copy link

netlify bot commented Jul 16, 2020

Deploy preview for gestalt ready!

Built with commit 01a5eaa

https://deploy-preview-1057--gestalt.netlify.app

@netlify
Copy link

netlify bot commented Jul 16, 2020

Deploy preview for gestalt ready!

Built with commit fa3f23b

https://deploy-preview-1057--gestalt.netlify.app

@AlbertCarreras AlbertCarreras marked this pull request as draft July 17, 2020 00:39
@AlbertCarreras AlbertCarreras force-pushed the checkbox branch 2 times, most recently from 7dd6f16 to 519eee2 Compare July 17, 2020 01:53
@christianvuerings christianvuerings added the major release Major release label Jul 17, 2020
@mergify mergify bot merged commit 1a11bce into pinterest:master Jul 17, 2020
@@ -104,7 +113,7 @@ export default function Checkbox({
marginRight={-1}
>
<Label htmlFor={id}>
<Box paddingX={1} position="relative">

Choose a reason for hiding this comment

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

This position relative is need as the input element is position absolute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major release Major release
Projects
None yet
3 participants