From c7b8be8a4b703b44a527a25945061eb234735310 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Thu, 15 Feb 2018 21:01:21 -0500 Subject: [PATCH] Writing Flow: Avoid auto-focus on nested blocks --- editor/components/writing-flow/index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/editor/components/writing-flow/index.js b/editor/components/writing-flow/index.js index 7fe3a5ee3f60ff..24762d6f4eb4da 100644 --- a/editor/components/writing-flow/index.js +++ b/editor/components/writing-flow/index.js @@ -261,6 +261,14 @@ class WritingFlow extends Component { const blockContainer = this.container.querySelector( `[data-block="${ this.props.selectedBlockUID }"]` ); if ( blockContainer && ! blockContainer.contains( document.activeElement ) ) { const target = this.getInnerTabbable( blockContainer, this.props.initialPosition === -1 ); + + // Avoid selecting the target if it's: + // - The default block appender (or generally uneditable) + // - Within a nested block + if ( target.readOnly || target.closest( '[data-block]' ) !== blockContainer ) { + return; + } + target.focus(); if ( this.props.initialPosition === -1 ) { // Special casing RichText components because the two functions at the bottom are not working as expected.