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

Update: Show parent block as selected when there is content locking #43918

Merged
Changes from all 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
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