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 Library: Implement pass-through behavior for Column block #16024

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
16 changes: 15 additions & 1 deletion packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,27 @@ 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 ) {
blockWrapperProps = {
...blockWrapperProps,
...blockType.getEditWrapperProps( attributes ),
};

isFocusable = ! ( 'tabIndex' in blockWrapperProps ) || (
isFinite( blockWrapperProps.tabIndex ) &&
Number( blockWrapperProps.tabIndex ) !== '-1'
aduth marked this conversation as resolved.
Show resolved Hide resolved
);
}
const blockElementId = `block-${ clientId }`;

Expand Down Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions packages/block-editor/src/components/block-list/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
15 changes: 11 additions & 4 deletions packages/block-library/src/column/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down