-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Components: Implement Button as assigning ref via forwardRef #6527
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this.
If memory serves me, PostPermalink
was the only component using focus()
. I tested editing post permalinks and there are no regressions.
👍 once Travis CI is happy.
// Disable reason: This test is desirable, but unsupported by Enzyme in | ||
// the current version, as it depends on features new to React in 16.3.0. | ||
// | ||
// eslint-disable-next-line jest/no-disabled-tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we e.g. create an issue to remind us to unskip this in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we e.g. create an issue to remind us to unskip this in the future?
Created at #7005
Hmm, unfortunately seems to be another instance of Enzyme lagging behind React: enzymejs/enzyme#1604 Was able to implement the workaround for the buttons tests themselves, but will have to see what I can do for other components which render buttons (failing Autocomplete tests, for example). |
yes, this is pretty sad that they failed to upgrade to React 16.3 :( |
|
||
mount( <ButtonWithForwardedRef ref={ ref } /> ); | ||
|
||
expect( ref.current.nodeName ).toBe( 'button' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test will fail when unskipped: Element#nodeName
returns uppercase, so should be asserting as toBe( 'BUTTON' );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may take another few weeks until we can unskip those tests :(
The day when we remove Enzyme
is becoming a reality if there is no progress on supporting React 16.3+
This pull request seeks to bring in React's (new as of 16.3.0)
forwardRef
as an alternative solution for components which need to expose its internal DOM representation. AButton
abstraction is a perfect use case for this, where we expose an instance functionfocus
to recreate the native DOM behavior. Instead, we can simply forward theref
so that any parent component which assigns aref
toButton
will have its value assigned as the actual DOM node.Testing instructions:
Verify that there are no regressions in the behavior of button, particularly in the two places where its
ref
is used for focus: Permalinks returning focus after pressing "OK" on an edit, and similarly for Shared Blocks pressing "OK" on an edit, returning focus to the permalink and Edit buttons respectively.