Skip to content
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
20 changes: 10 additions & 10 deletions packages/edit-site/src/components/page-library/grid-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ export default function GridItem( { categoryId, composite, icon, item } ) {
canvas: 'edit',
} );

const onKeyDown = ( event ) => {
if ( DELETE === event.keyCode || BACKSPACE === event.keyCode ) {
setIsDeleteDialogOpen( true );
}
};

const isEmpty = ! item.blocks?.length;
const patternClassNames = classnames( 'edit-site-library__pattern', {
'is-placeholder': isEmpty,
Expand All @@ -72,8 +78,9 @@ export default function GridItem( { categoryId, composite, icon, item } ) {
}
};

const isUserPattern = item.type === USER_PATTERNS;
let ariaDescription;
if ( item.type === USER_PATTERNS ) {
if ( isUserPattern ) {
// User patterns don't have descriptions, but can be edited and deleted, so include some help text.
ariaDescription = __(
'Press Enter to edit, or Delete to delete the pattern.'
Expand All @@ -90,19 +97,12 @@ export default function GridItem( { categoryId, composite, icon, item } ) {
role="option"
as="div"
{ ...composite }
onClick={ item.type !== PATTERNS ? onClick : undefined }
onClick={ isUserPattern ? onClick : undefined }
onKeyDown={ isUserPattern ? onKeyDown : undefined }
aria-label={ item.title }
aria-describedby={
ariaDescription ? descriptionId : undefined
}
onKeyDown={ ( event ) => {
if (
DELETE === event.keyCode ||
BACKSPACE === event.keyCode
) {
setIsDeleteDialogOpen( true );
}
} }
>
{ isEmpty && __( 'Empty pattern' ) }
{ ! isEmpty && <BlockPreview blocks={ item.blocks } /> }
Expand Down