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

Image block: Caption toolbar is not dismissed when cropping image in place #30407

Conversation

ramonjd
Copy link
Member

@ramonjd ramonjd commented Mar 31, 2021

Description

When editing an image caption, clicking on the image itself dismisses the caption toolbar. This is normal and expected.

However, when we click on the image's caption field while cropping an image in place, we can't dismiss the toolbar without cancelling image crop mode.

Furthermore the caption field refuses to yield focus. 🤷

This PR passes an onBlur handler down to the RichText package, and blurs the caption field when the field loses focus.

This needs to be tested in conjunction with #30587 as the RichText package doesn't currently handle an onBlur callback

We're also blurring away from the caption field when the caption field loses focus.

Resolves #30334

Also remarked upon in #23350 (comment)

How has this been tested?

Manually on desktop and a mobile emulator.

Testing

  1. Check out this PR and also RichText: add onBlur prop to so onBlur callback from block-editor can be plumbed through #30587
  2. Select an image in the editor
  3. Click the crop button in the toolbar
  4. Check that the caption toolbar is dismissed

The caption toolbar should now disappear and the caption field should lose focus.

Screenshots

Before

Mar-31-2021 22-17-26

After

Mar-31-2021 22-13-47

Types of changes

This is a minor bugfix for an existing block (image).

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

…we have to add an onclick to the cropper container. This is similar to what we do when not editing the image. We're also blurring away from the caption field when the caption field loses focus.
- Added a key event handler to the cropper wrapper
- Added a role attribute with a value of img (A container for a collection of elements that form an image.) an descriptive aria label
@ramonjd ramonjd force-pushed the add/image-block-onclick-to-blur-and-close-caption branch from 7e15bd8 to 9733917 Compare March 31, 2021 23:04
@@ -51,6 +52,10 @@ export default function ImageCropper( {
width: width || clientWidth,
height: editedHeight,
} }
onClick={ onClick }
onKeyDown={ onClick }
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not entirely sure how accessible this is via keyboard anyway.

Are folks happy with adding a

// eslint-disable-next-line jsx-a11y/no-static-element-interactions

to disable for now?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have any objections to disabling the no-static-element-interactions linting for this. It appears to be done in a dozen or more places already.

The accessibility concerns here aren't my strong suit so happy to defer to others there.

@aaronrobertshaw aaronrobertshaw self-requested a review April 1, 2021 01:15
Copy link
Contributor

@aaronrobertshaw aaronrobertshaw left a comment

Choose a reason for hiding this comment

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

This is testing well for me 👍

The simplicity of being able to click on the image to blur the caption field feels intuitive. Even if the caption field retains focus when selecting options from the cropping toolbar, it is simple to click the image if the caption toolbar is in the way.

I'm happy to give this a tentative approval now but will be good to get some extra eyes on it all the same 🙂

@glendaviesnz glendaviesnz added [Block] Image Affects the Image Block [Type] Bug An existing feature does not function as intended labels Apr 1, 2021
@glendaviesnz
Copy link
Contributor

@ramonjd I wonder if we should look for a solution at the richtext toolbar level as the same issue occurs with gallery caption, and I am picking anywhere this component is used?

caption-toolbar-dismiss

@glendaviesnz
Copy link
Contributor

Looks like RichText focus management is a longstanding issue - #9740

@ramonjd
Copy link
Member Author

ramonjd commented Apr 7, 2021

I wonder if we should look for a solution at the richtext toolbar level as the same issue occurs with gallery caption, and I am picking anywhere this component is used?

Thanks for looking more closely at this @glendaviesnz

I agree it makes sense to try to address it at the higher level and start a discussion on the best way to approach it.

@@ -540,6 +540,13 @@ export default function Image( {
);
}

function onCaptionBlur() {
if ( captionFocused ) {
captionRef.current.blur();
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think we need this ref.blur if #30587 lands.

@ramonjd
Copy link
Member Author

ramonjd commented Apr 12, 2021

On hold until we resolve a neat way to handle onBlue on RichText components. See: #30587

@ramonjd ramonjd closed this Apr 12, 2021
@ramonjd ramonjd deleted the add/image-block-onclick-to-blur-and-close-caption branch July 4, 2021 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Image Affects the Image Block [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gallery block refactor: Caption toolbar is not dismissed when cropping image in place
3 participants