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

List View: Display lock status #40088

Merged
merged 3 commits into from
Apr 7, 2022
Merged
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
36 changes: 34 additions & 2 deletions packages/block-editor/src/components/list-view/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import {
Button,
__experimentalTreeGridCell as TreeGridCell,
__experimentalTreeGridItem as TreeGridItem,
} from '@wordpress/components';
import { useInstanceId } from '@wordpress/compose';
import { moreVertical } from '@wordpress/icons';
import { lock, moreVertical } from '@wordpress/icons';
import {
useState,
useRef,
useEffect,
useCallback,
memo,
} from '@wordpress/element';
import { useDispatch } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';
import { sprintf, __ } from '@wordpress/i18n';

/**
Expand Down Expand Up @@ -68,6 +69,15 @@ function ListViewBlock( {
level
);

const isLocked = useSelect(
( select ) => {
const { canMoveBlock, canRemoveBlock } = select( blockEditorStore );

return ! canMoveBlock( clientId ) || ! canRemoveBlock( clientId );
},
[ clientId ]
);
Mamaduka marked this conversation as resolved.
Show resolved Hide resolved

const blockAriaLabel = blockInformation
? sprintf(
// translators: %s: The title of the block. This string indicates a link to select the block.
Expand Down Expand Up @@ -274,6 +284,28 @@ function ListViewBlock( {
</>
) }

{ isLocked && (
<TreeGridCell
className="block-editor-list-view-block__lock-cell"
aria-selected={ !! isSelected }
>
{ ( { ref, tabIndex, onFocus } ) => (
<Button
disabled
ref={ ref }
tabIndex={ tabIndex }
onFocus={ onFocus }
icon={ lock }
label={ sprintf(
/* translators: %s: block name */
__( 'Locked %s' ),
blockInformation.title
) }
/>
) }
</TreeGridCell>
) }
Copy link
Contributor

@talldan talldan Apr 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can be simpler than making it a button in a cell, the cells should only really be used for focusable elements. An alternative would be to add it to the ListViewBlockSelectButton component as an Icon, after the anchor (https://github.com/WordPress/gutenberg/blob/trunk/packages/block-editor/src/components/list-view/block-select-button.js). That component's children are laid out using flexbox, so hopefully the icon can be made to justify/align itself at the end. I think you'd hopefully then be able to use the similar CSS to the block icon to make it switch between black and white on block selection.

The other part that I think should be tackled is announcing the locked status to screenreaders.

I was having a look to see how the selected block is announced so that this could be done in the same way, but I can't see it in the code. There might have been a regression.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving status icon into ListViewBlockSelectButton makes sense.

The other part that I think should be tackled is announcing the locked status to screenreaders.

You're right. Currently, locked blocks aren't announced. I am adding this issue to my to-do list. Thanks for checking and catching the issue, @talldan.


{ showBlockActions && (
<TreeGridCell
className={ listViewBlockSettingsClassName }
Expand Down
12 changes: 12 additions & 0 deletions packages/block-editor/src/components/list-view/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@
}
}

.block-editor-list-view-block__lock-cell {
line-height: 0;
width: 24px;
min-width: 24px;
padding: 0;
vertical-align: middle;

.components-button:disabled {
opacity: 1;
}
}

.block-editor-list-view-block__mover-cell-alignment-wrapper {
display: flex;
height: 100%;
Expand Down