Skip to content

Commit

Permalink
Update: Show parent block as selected when there is content locking
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Sep 8, 2022
1 parent 4efdb49 commit 4d8fbf3
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions packages/block-editor/src/components/list-view/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 }
>
<TreeGridCell
className="block-editor-list-view-block__contents-cell"
colSpan={ colSpan }
ref={ cellRef }
aria-label={ blockAriaLabel }
aria-selected={ !! isSelected }
aria-selected={ !! isSelected || forceSelectionContentLock }
aria-expanded={ isContentLocked ? undefined : isExpanded }
aria-describedby={ descriptionId }
>
Expand Down Expand Up @@ -283,7 +302,7 @@ function ListViewBlock( {
{ showBlockActions && (
<TreeGridCell
className={ listViewBlockSettingsClassName }
aria-selected={ !! isSelected }
aria-selected={ !! isSelected || forceSelectionContentLock }
>
{ ( { ref, tabIndex, onFocus } ) => (
<BlockSettingsDropdown
Expand Down

0 comments on commit 4d8fbf3

Please sign in to comment.