From 4449cd60c7202dacf613793a7095b0237ea7d69e Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Thu, 6 Jun 2019 15:09:11 -0400 Subject: [PATCH 1/3] Block Editor: Disable block selection via tabIndex focus disabling --- .../src/components/block-list/block.js | 16 +++++++++++++++- .../src/components/block-list/style.scss | 10 ++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/block-list/block.js b/packages/block-editor/src/components/block-list/block.js index aac68e2e6faa8..96497674c8fd5 100644 --- a/packages/block-editor/src/components/block-list/block.js +++ b/packages/block-editor/src/components/block-list/block.js @@ -400,6 +400,15 @@ function BlockListBlock( { className ); + // By default, a block is focusable, which enables it to be set as the + // selected block when the user interacts within its content. Through + // assignment of its wrapper props, however, a block can opt-out of this + // behavior to effectively treat the block as a "pass-through", one which + // is not intended to be directly selected under normal circumstances. + // Often this occurs in the context of deep block nesting, where focus + // selection instead occurs by one of the ancestor blocks. + let isFocusable = true; + // Determine whether the block has props to apply to the wrapper. let blockWrapperProps = wrapperProps; if ( blockType.getEditWrapperProps ) { @@ -407,6 +416,11 @@ function BlockListBlock( { ...blockWrapperProps, ...blockType.getEditWrapperProps( attributes ), }; + + isFocusable = ! ( 'tabIndex' in blockWrapperProps ) || ( + isFinite( blockWrapperProps.tabIndex ) && + Number( blockWrapperProps.tabIndex ) !== '-1' + ); } const blockElementId = `block-${ clientId }`; @@ -452,7 +466,7 @@ function BlockListBlock( { className={ wrapperClassName } data-type={ name } onTouchStart={ onTouchStart } - onFocus={ onFocus } + onFocus={ isFocusable ? onFocus : null } onClick={ onTouchStop } onKeyDown={ deleteOrInsertAfterWrapper } tabIndex="0" diff --git a/packages/block-editor/src/components/block-list/style.scss b/packages/block-editor/src/components/block-list/style.scss index 8ee3558ddf639..45e6c948d6439 100644 --- a/packages/block-editor/src/components/block-list/style.scss +++ b/packages/block-editor/src/components/block-list/style.scss @@ -316,6 +316,16 @@ } } + // Disable clickthrough overlay for blocks which aren't focusable, since + // overlay depends on dismissal by selection. This effectively treats the + // block as a "pass-through", one which is not intended to be selected + // through standard focus interactions. + &[tabindex="-1"], + &:not([tabindex]) { + > .block-editor-block-list__block-edit .block-editor-inner-blocks.has-overlay::after { + display: none; + } + } // Alignments &[data-align="left"], From 0aa41cfe9db2f3f1cb0c9cb75bd263c9e753ac1c Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Thu, 6 Jun 2019 15:18:54 -0400 Subject: [PATCH 2/3] Block Library: Add pass-through wrapper prop for Column block --- packages/block-library/src/column/index.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/block-library/src/column/index.js b/packages/block-library/src/column/index.js index 250ce0bad65a4..2f6b98614f2c7 100644 --- a/packages/block-library/src/column/index.js +++ b/packages/block-library/src/column/index.js @@ -27,13 +27,20 @@ export const settings = { }, getEditWrapperProps( attributes ) { const { width } = attributes; + + // A column should act as a "pass-through", meaning that it cannot be + // selected by typical focus interactions. A block becomes selected by + // virtue of its focus handler, and by nullifying its tabIndex, it will + // no longer handle focus events. + const props = { tabIndex: undefined }; + if ( Number.isFinite( width ) ) { - return { - style: { - flexBasis: width + '%', - }, + props.style = { + flexBasis: width + '%', }; } + + return props; }, edit, save, From 0651a4524bd5f4a41fe7440f7b506b3b842e50ed Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Mon, 10 Jun 2019 09:41:47 -0400 Subject: [PATCH 3/3] Block Editor: Compare coerced tabIndex as number MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Grzegorz (Greg) Ziółkowski --- packages/block-editor/src/components/block-list/block.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/block-list/block.js b/packages/block-editor/src/components/block-list/block.js index 96497674c8fd5..d5a70b040639d 100644 --- a/packages/block-editor/src/components/block-list/block.js +++ b/packages/block-editor/src/components/block-list/block.js @@ -419,7 +419,7 @@ function BlockListBlock( { isFocusable = ! ( 'tabIndex' in blockWrapperProps ) || ( isFinite( blockWrapperProps.tabIndex ) && - Number( blockWrapperProps.tabIndex ) !== '-1' + Number( blockWrapperProps.tabIndex ) !== -1 ); } const blockElementId = `block-${ clientId }`;