-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Leverage forwardRef to remove findDOMNode from the block component #11170
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ import { get, reduce, size, first, last } from 'lodash'; | |
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Component, findDOMNode, Fragment } from '@wordpress/element'; | ||
import { Component, Fragment } from '@wordpress/element'; | ||
import { | ||
focus, | ||
isTextField, | ||
|
@@ -102,24 +102,12 @@ export class BlockListBlock extends Component { | |
} | ||
|
||
setBlockListRef( node ) { | ||
// Disable reason: The root return element uses a component to manage | ||
// event nesting, but the parent block list layout needs the raw DOM | ||
// node to track multi-selection. | ||
// | ||
// eslint-disable-next-line react/no-find-dom-node | ||
node = findDOMNode( node ); | ||
|
||
this.wrapperNode = node; | ||
|
||
this.props.blockRef( node, this.props.clientId ); | ||
} | ||
|
||
bindBlockNode( node ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this ref (bindBlockNode), it seems we can use createRef in the constructor. But I'm not sure if it is beneficial or has any advantage besides saving one or two lines of code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can probably use |
||
// Disable reason: The block element uses a component to manage event | ||
// nesting, but we rely on a raw DOM node for focusing. | ||
// | ||
// eslint-disable-next-line react/no-find-dom-node | ||
this.node = findDOMNode( node ); | ||
this.node = node; | ||
} | ||
|
||
/** | ||
|
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.
Not related but something I noticed while reviewing. The parent passes the clientId and a callback function blockRef that receives the node and the clientId, passing the clientId here seems unnecessary the parent can pass a normal ref function blockRef specific for each cliendId.