Repository navigation
Description
When setting a Featured Image, the Media Modal opens. The Media Modal takes care of moving focus back to the "opener" element when it closes. This is the button that opened the modal.
However, the "Set featured image" button gets removed from the DOM
gutenberg/packages/editor/src/components/post-featured-image/index.js
Lines 88 to 104 in d7a4dfa
| { ! featuredImageId && | |
| <div> | |
| <MediaUploadCheck fallback={ instructions }> | |
| <MediaUpload | |
| title={ postLabel.featured_image || DEFAULT_FEATURE_IMAGE_LABEL } | |
| onSelect={ onUpdateImage } | |
| allowedTypes={ ALLOWED_MEDIA_TYPES } | |
| modalClass="editor-post-featured-image__media-modal" | |
| render={ ( { open } ) => ( | |
| <Button className="editor-post-featured-image__toggle" onClick={ open }> | |
| { postLabel.set_featured_image || DEFAULT_SET_FEATURE_IMAGE_LABEL } | |
| </Button> | |
| ) } | |
| /> | |
| </MediaUploadCheck> | |
| </div> | |
| } |
There's no reference any longer to the opener element and the Media Modal can't move focus back to it.
As accessibility team, we've warned many times special care should be taken when removing, hiding, or disabling "focus-candidate" elements from the DOM. In the case of modals, focus should always be moved back to a proper place in the "invoking context".
Focus losses need to be avoided because they're a terrible experience for keyboard and screen reader users. Even though modern browsers have implemented a sort of sequential focus navigation starting point that just tries to keep focus "in place" and, technically, there's no focused element. Also, it's not guaranteed to work, especially when using assistive technologies.
We've seen other cases in Gutenberg where a mechanism to determine a fallback where focus should be moved back would be useful. Not sure how to implement it.
In this specific case, worth noting the image preview is a button: specifically, a MediaUploadCheck component that renders also a button. I guess using the same MediaUploadCheck for both the "Set featured image" button and the image preview button could solve the issue.
Activity