Skip to content

Commit

Permalink
Fix delete shortcut incorrectly bound to non-user patterns (#51830)
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan authored and tellthemachines committed Jun 27, 2023
1 parent 340833e commit 64ed918
Showing 1 changed file with 10 additions and 10 deletions.
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

0 comments on commit 64ed918

Please sign in to comment.