Skip to content

Commit

Permalink
Block List: Capture focus event on block wrapper
Browse files Browse the repository at this point in the history
Corresponding to move of tabIndex from inner edit element to wrapper, we also need to capture focus from wrapper. This way, when focus is applied via WritingFlow, the block appropriately becomes selected. This may also make "onSelect" of movers unnecessary.
  • Loading branch information
aduth committed Mar 6, 2018
1 parent 95a4d31 commit 4a85e23
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions editor/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ export class BlockListBlock extends Component {
// eslint-disable-next-line react/no-find-dom-node
node = findDOMNode( node );

this.wrapperNode = node;

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

Expand All @@ -214,7 +216,11 @@ export class BlockListBlock extends Component {
focusTabbable() {
const { initialPosition } = this.props;

if ( this.node.contains( document.activeElement ) ) {
// Focus is captured by the wrapper node, so while focus transition
// should only consider tabbables within editable display, since it
// may be the wrapper itself or a side control which triggered the
// focus event, don't unnecessary transition to an inner tabbable.
if ( this.wrapperNode.contains( document.activeElement ) ) {
return;
}

Expand Down Expand Up @@ -578,14 +584,14 @@ export class BlockListBlock extends Component {
className={ wrapperClassName }
data-type={ block.name }
onTouchStart={ this.onTouchStart }
onFocus={ this.onFocus }
onClick={ this.onClick }
tabIndex="0"
childHandledEvents={ [
'onKeyPress',
'onDragStart',
'onMouseDown',
'onKeyDown',
'onFocus',
] }
{ ...wrapperProps }
>
Expand Down Expand Up @@ -618,7 +624,6 @@ export class BlockListBlock extends Component {
onDragStart={ this.preventDrag }
onMouseDown={ this.onPointerDown }
onKeyDown={ this.onKeyDown }
onFocus={ this.onFocus }
className="editor-block-list__block-edit"
aria-label={ blockLabel }
data-block={ block.uid }
Expand Down

0 comments on commit 4a85e23

Please sign in to comment.