Skip to content
This repository has been archived by the owner on Aug 24, 2018. It is now read-only.

Fix accessibility issues with image widget #50

Merged
merged 5 commits into from
Apr 8, 2017

Conversation

westonruter
Copy link
Contributor

Fixes #47

@westonruter westonruter changed the title [WIP] Fix accessibility issues with image widget Fix accessibility issues with image widget Apr 6, 2017
Copy link
Contributor

@timmyc timmyc left a comment

Choose a reason for hiding this comment

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

One minor note about the debounce usage added here, otherwise this is testing out well for me.

@@ -111,7 +111,9 @@ wp.mediaWidgets = ( function( $ ) {

// Re-render the preview when the attachment changes.
control.selectedAttachment = new wp.media.model.Attachment( { id: 0 } );
control.renderPreview = _.debounce( control.renderPreview );
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe, though I could be wrong, that renderPreview is only called when the media modal is closed when the 'Update' button is clicked... if the dialog is closed with the 'x' or hitting the escape key, the model is not updated and renderPreview is not called. So not sure if we need to debounce this or not...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason I added the debounce is because the preview is also now re-rendering in due to changes to control.model. So when you change the media, it will result the model being changed (the attachment_id and url props) as well as the selectedAttachment model, resulting in renderPreview being called twice. So this was intended to be a minor DOM performance improvement to not waste cycles.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha, so this saves one render in instances where you are changing media/url. Looks like the preview is rendered twice upon initial load as well when the model is being updated. While playing with this I noticed renderPreview is called on each keystroke when editing the widget title currently so perhaps that is a good candidate for a _.throttle if we are concerned about too many renders.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The preview rendering is separate. It actually already has throttling via the Customizer in two places. If you type quickly you'll note that the preview doesn't update until you slow down. Debouncing the updates to the widget instance settings is currently handled here: https://github.com/WordPress/wordpress-develop/blob/4.7.3/src/wp-admin/js/customize-widgets.js#L887-L889

The selective refresh of the widget in the preview also gets debounced here: https://github.com/WordPress/wordpress-develop/blob/4.7.3/src/wp-includes/js/customize-selective-refresh.js#L684-L712

And full refreshes are debounced here: https://github.com/WordPress/wordpress-develop/blob/4.7.3/src/wp-admin/js/customize-controls.js#L3655-L3677

For the core fix to reduce the number of preview refreshes in rapid succession, such as with implementing a decay, see https://core.trac.wordpress.org/ticket/38954

Copy link
Contributor

@timmyc timmyc Apr 6, 2017

Choose a reason for hiding this comment

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

Great stuff, thanks for those links... so much to learn here. So here is the renderPreview bit in action in the widget itself. I've hacked the alt attribute in the renderPreview method to show how many times it is called. Note that the number increments with each keystroke of the title which is triggering the change on control.model. This is happening in master here too, mis-spoke there, it is the addition of control.listenTo( control.model, 'change', control.renderPreview ); that causes the preview to re-render whenever the title changes.

refresh

Copy link
Contributor

@timmyc timmyc left a comment

Choose a reason for hiding this comment

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

I think this is good to go, but perhaps @afercia can give it the final 👍

@afercia
Copy link

afercia commented Apr 6, 2017

Would it be possible to put the filename in the alt when the alt is empty?

@westonruter
Copy link
Contributor Author

@afercia Yes, but isn't that the behavior for screen readers when the alt is absent?

@afercia
Copy link

afercia commented Apr 6, 2017

@westonruter yes but I'd like to avoid a missing alt. We've discussed a bit this on Slack with Joe Dolson, I think he's going to comment :)

@joedolson
Copy link

Had a conversation with @afercia about the alt attribute issue, and there is some ambiguity about it. A user with a screen reader needs to know what the image they've added is, which would generally be presented via the alt attribute. However, because they're in an editing context, they also need to be able to distinguish between the alt attribute that will be present on the front end and what they see in the admin.

We hypothesized a solution where the alt attribute is given context, such as an aria-describedby with "Current image: {alt attribute or filename}", or appending text to the alt attribute to indicate that the text is only available because the user is currently editing.

In thinking about this, it seems like adding the alt attribute as it would appear on the front-end, then also adding an aria-describedby description which indicates what the current image is would be best, but it may require some user testing to see how clearly this is presented by the screen readers.

@afercia
Copy link

afercia commented Apr 6, 2017

This is the result of s quick test, only run on Safari+VoiceOver. The image preview has an empty alt attribute and an aria-describedby targeting a hidden paragraph:

screen shot 2017-04-06 at 22 33 29

<img class="attachment-thumb" src="{{ data.attachment.url }}" draggable="false" alt="" aria-describedby="image-info" />
<p class="hidden" id="image-info">Current image: bla bla</p>

just a rough test, the aria-describedby and the hidden paragraph should probably be printed out only when the alt is empty. Also, would need more testing with other AT combos and a better wording.

@westonruter
Copy link
Contributor Author

@afercia @joedolson how is b4146ab?

What also about the .not-selected element, while it is hidden will it be a problem for screen readers?:

image

@westonruter
Copy link
Contributor Author

What also about the .not-selected element, while it is hidden will it be a problem for screen readers?:

This is fixed in c19a07b.

@westonruter westonruter merged commit b060e77 into master Apr 8, 2017
@westonruter
Copy link
Contributor Author

Please advise if additional changes are needed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants