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

Block gallery: delete image with delete or backspace keys #14822

Merged
merged 3 commits into from
Apr 12, 2019
Merged
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
17 changes: 9 additions & 8 deletions packages/block-library/src/gallery/gallery-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class GalleryImage extends Component {
constructor() {
super( ...arguments );

this.onImageClick = this.onImageClick.bind( this );
this.onSelectImage = this.onSelectImage.bind( this );
this.onSelectCaption = this.onSelectCaption.bind( this );
this.onKeyDown = this.onKeyDown.bind( this );
this.onRemoveImage = this.onRemoveImage.bind( this );
this.bindContainer = this.bindContainer.bind( this );
oandregal marked this conversation as resolved.
Show resolved Hide resolved

this.state = {
Expand All @@ -44,7 +44,7 @@ class GalleryImage extends Component {
}
}

onImageClick() {
onSelectImage() {
if ( ! this.props.isSelected ) {
this.props.onSelect();
}
Expand All @@ -56,7 +56,7 @@ class GalleryImage extends Component {
}
}

onKeyDown( event ) {
onRemoveImage( event ) {
if (
this.container === document.activeElement &&
this.props.isSelected && [ BACKSPACE, DELETE ].indexOf( event.keyCode ) !== -1
Expand Down Expand Up @@ -108,11 +108,12 @@ class GalleryImage extends Component {
src={ url }
alt={ alt }
data-id={ id }
onClick={ this.onImageClick }
onFocus={ this.onImageClick }
onKeyDown={ this.onImageClick }
onClick={ this.onSelectImage }
onFocus={ this.onSelectImage }
onKeyDown={ this.onRemoveImage }
tabIndex="0"
aria-label={ ariaLabel }
ref={ this.bindContainer }
/>
{ isBlobURL( url ) && <Spinner /> }
</Fragment>
Expand All @@ -127,7 +128,7 @@ class GalleryImage extends Component {
// Disable reason: Each block can be selected by clicking on it and we should keep the same saved markup
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */
return (
<figure className={ className } tabIndex="-1" onKeyDown={ this.onKeyDown } ref={ this.bindContainer }>
<figure className={ className }>
oandregal marked this conversation as resolved.
Show resolved Hide resolved
{ isSelected &&
<div className="block-library-gallery-item__inline-menu">
<IconButton
Expand Down