From 4d8fbf3549893696612181a43b5a74503a9ce6a1 Mon Sep 17 00:00:00 2001 From: Jorge Date: Tue, 6 Sep 2022 17:05:25 +0100 Subject: [PATCH] Update: Show parent block as selected when there is content locking --- .../src/components/list-view/block.js | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/packages/block-editor/src/components/list-view/block.js b/packages/block-editor/src/components/list-view/block.js index 083d6238708977..4d5e2e7ea8c49f 100644 --- a/packages/block-editor/src/components/list-view/block.js +++ b/packages/block-editor/src/components/list-view/block.js @@ -58,11 +58,31 @@ function ListViewBlock( { const cellRef = useRef( null ); const [ isHovered, setIsHovered ] = useState( false ); const { clientId } = block; + + const { isLocked, isContentLocked } = useBlockLock( clientId ); + const forceSelectionContentLock = useSelect( + ( select ) => { + if ( isSelected ) { + return false; + } + if ( ! isContentLocked ) { + return false; + } + return select( blockEditorStore ).hasSelectedInnerBlock( + clientId, + true + ); + }, + [ isContentLocked, clientId, isSelected ] + ); + const isFirstSelectedBlock = - isSelected && selectedClientIds[ 0 ] === clientId; + forceSelectionContentLock || + ( isSelected && selectedClientIds[ 0 ] === clientId ); const isLastSelectedBlock = - isSelected && - selectedClientIds[ selectedClientIds.length - 1 ] === clientId; + forceSelectionContentLock || + ( isSelected && + selectedClientIds[ selectedClientIds.length - 1 ] === clientId ); const { toggleBlockHighlight } = useDispatch( blockEditorStore ); @@ -80,7 +100,6 @@ function ListViewBlock( { '__experimentalToolbar', true ); - const { isLocked, isContentLocked } = useBlockLock( clientId ); const instanceId = useInstanceId( ListViewBlock ); const descriptionId = `list-view-block-select-button__${ instanceId }`; const blockPositionDescription = getBlockPositionDescription( @@ -181,7 +200,7 @@ function ListViewBlock( { } const classes = classnames( { - 'is-selected': isSelected, + 'is-selected': isSelected || forceSelectionContentLock, 'is-first-selected': isFirstSelectedBlock, 'is-last-selected': isLastSelectedBlock, 'is-branch-selected': isBranchSelected, @@ -211,14 +230,14 @@ function ListViewBlock( { id={ `list-view-block-${ clientId }` } data-block={ clientId } isExpanded={ isContentLocked ? undefined : isExpanded } - aria-selected={ !! isSelected } + aria-selected={ !! isSelected || forceSelectionContentLock } > @@ -283,7 +302,7 @@ function ListViewBlock( { { showBlockActions && ( { ( { ref, tabIndex, onFocus } ) => (