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

Block: Assign block list ref from block child #3205

Merged
merged 1 commit into from
Oct 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions editor/modes/visual-editor/block-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,8 @@ class VisualEditorBlockList extends Component {
this.lastClientY = clientY;
}

setBlockRef( ref ) {
// To avoid dynamically creating function references for ref on every
// block element, instead reach into props of element directly.
const uid = ref.props.uid;

// Disable reason: We use DOM nodes of each rendered block in the list
// to determine multi-selection thresholds.
// eslint-disable-next-line react/no-find-dom-node
const node = findDOMNode( ref );

if ( ref === null ) {
setBlockRef( node, uid ) {
if ( node === null ) {
delete this.nodes[ uid ];
} else {
this.nodes = {
Expand Down Expand Up @@ -204,7 +195,7 @@ class VisualEditorBlockList extends Component {
<VisualEditorBlock
key={ 'block-' + uid }
uid={ uid }
ref={ this.setBlockRef }
blockRef={ this.setBlockRef }
onSelectionStart={ this.onSelectionStart }
onShiftSelection={ this.onShiftSelection }
/>,
Expand Down
6 changes: 6 additions & 0 deletions editor/modes/visual-editor/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class VisualEditorBlock extends Component {
constructor() {
super( ...arguments );

this.setBlockListRef = this.setBlockListRef.bind( this );
this.bindBlockNode = this.bindBlockNode.bind( this );
this.setAttributes = this.setAttributes.bind( this );
this.maybeHover = this.maybeHover.bind( this );
Expand Down Expand Up @@ -135,6 +136,10 @@ class VisualEditorBlock extends Component {
document.removeEventListener( 'mousemove', this.stopTypingOnMouseMove );
}

setBlockListRef( node ) {
this.props.blockRef( node, this.props.uid );
}

bindBlockNode( node ) {
this.node = node;
}
Expand Down Expand Up @@ -339,6 +344,7 @@ class VisualEditorBlock extends Component {
/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */
return (
<div
ref={ this.setBlockListRef }
onMouseMove={ this.maybeHover }
onMouseEnter={ this.maybeHover }
onMouseLeave={ onMouseLeave }
Expand Down