-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Insert link accessibility #1933
Conversation
## Description Fixes WordPress#694 by improving the screen reader accessibility of the element. My updates apply to the add link and edit link pop-out elements, handling the following aspects: - The buttons (Apply, Edit, Remove) now have the aria-label attribute added in for accessibility purposes. There is no visual change for them. - The URL input now has an ID that makes use of the withInstanceId feature from components - The URL input now has a screen-reader-text label which uses the ID on the for attribute to improve the screen reader accessibility of the element. This label is not visible. ## How Has This Been Tested? I used the browser's inspector (screenshots reflect that) to confirm the presence of the a11y attributes and screen-reader-text elements on both the add link and edit link forms. The updates done in blocks/editable/format-toolbar.js were visible in the add link / edit existing link workflow in the text block, just like the screenshots show. I wasn't able to figure out where is the "blocks/library/button/index.js" actually used. It has in the edit function a form with a class of editable-format-toolbar__link-modal, just like the one generated with the insert/edit URL. Locally only I tried adding an extra class on the form.editable-format-toolbar__link-modal and trying to hunt it in the browser, but I wasn't able to stumble upon it myself. That's why the changes done on that file are minimal (added the button aria-label and added a <label for> and added an ID to the URL input element itself, without making use of withInstanceId - because there is no export default I could add the withInstanceId call around). ## Screenshots: Add link form: ![Add link](http://files.urldocs.com/share/add-link/add-link.jpg "Add link form") Edit link form: ![Edit link](http://files.urldocs.com/share/edit-link/edit-link.jpg "Edit link form") ## Types of changes New feature (non-breaking change which adds functionality). ## Checklist: - [x] My code is tested. - [x] My code follows the WordPress code style.
blocks/editable/format-toolbar.js
Outdated
@@ -151,17 +152,24 @@ class FormatToolbar extends Component { | |||
className="editable-format-toolbar__link-modal" | |||
style={ linkStyle } | |||
onSubmit={ this.submitLink }> | |||
<label |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any difference between a visually-hidden label
for screen reader purposes, vs. using the aria-label
attribute on the input itself?
@afercia Would you have insight here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It really depends on a case by case basis. For form elements, a proper <label>
element is always preferable. I would say a proper visible label 🙂 (so they can also be clicked). On the other hand, screen-reader-text
is basically a hack, the only advantage is that it's understandable by any software reading the page source, even if the software doesn't understand ARIA. Still a hack though. There are historical reasons for screen-reader-text, since a few years ago not all the major screen readers fully supported ARIA. Today, aria-label
is more standard, but one of the first rule of ARIA is: do not use unless you really really have to.
Both a <label>
element and an aria-label
element contribute to the accessible name calculation and are equivalent in this regard. Overall, in this specific case, given the design constraints, I'd say go with aria-label.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have't found a resource to list what the current assistive technology software is supporting, and whether aria-label functions in a similar way to the visually hidden label.
The aria is the "W3C" way to handle such a scenario.
I've just tested VoiceOver on the mac and it reads out loud the aria-label, just like it does with the hidden label.
I've looked at a survey from 2 years ago:
http://webaim.org/projects/screenreadersurvey6/
and the charts were lead by commercial screen reader software applications - Jaws / ZoomText and Window Eyes.
Free solutions like NVDA and VoiceOver had a lower usage percentage.
And if this worked in VoiceOver, I would say that the commercial ones should support this just as well.
Really good input on this, @aduth !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@afercia
My opinion is that if JAWS (the screen reader which used to be the only one in town) supports aria-label, we should go ahead and use that instead of the visually hidden ones.
Is there any way we can find out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've asked a tester and the overall input was that ARIA is well supported amongst the popular screen readers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mehigh there's no need to ask around, we know the stuff 😉 what I've said is that a few years ago ARIA was not fully supported yet, today it is. We should also consider that a percentage of users might still use old screen reader versions since, especially the commercial ones like JAWS, they are pretty expensive. However, I'm OK with using aria-label but if you want to learn more you should really read the 5 rules of ARIA usage:
https://www.w3.org/TR/using-aria/
First one:
If you can use a native HTML element [HTML51] or attribute with the semantics and behaviour you require already built in, instead of re-purposing an element and adding an ARIA role, state or property to make it accessible, then do so.
That'e because ARIA shouldn't ever be used as something to "magically" fix things: always prefer native HTML instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@afercia
I think it makes sense to use aria-label in this specific environment because it simplifies the implementation by quite a bit.
My only hope is that JAWS has support for aria, just like how the other popular screen readers do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latest JAWS version support ARIA, since a few years.
because it simplifies the implementation by quite a bit
This is really the latest reason why one should use ARIA 🙂 and that's what I was trying to explain above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blocks/library/button/index.js
Outdated
@@ -60,20 +61,27 @@ registerBlockType( 'core/button', { | |||
<form | |||
className="editable-format-toolbar__link-modal" | |||
onSubmit={ ( event ) => event.preventDefault() }> | |||
<label |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question as above. Might avoid need for instanceId
altogether.
I've added the aria-label. Thanks for your reference, afercia. I'll read it through. |
blocks/editable/format-toolbar.js
Outdated
@@ -155,13 +155,17 @@ class FormatToolbar extends Component { | |||
autoFocus | |||
className="editable-format-toolbar__link-input" | |||
type="url" | |||
aria-label={ | |||
/* translators: accessibility text */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know that translator comment is necessary here, because unlike something like "(opens in new window)", "URL" is not a string that needs clarification by its context here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just discarded the translator comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The back-and-forth is a bit unclear, but my impression is that we're okay to move forward with aria-label
, in which case this looks good to me.
* Update ref * Update ref to point to gutenberg master
Description
Fixes #694 by improving the screen reader accessibility of the element.
My updates apply to the add link and edit link pop-out elements,
handling the following aspects:
added in for accessibility purposes. There is no visual change for them.
feature from components
the for attribute to improve the screen reader accessibility of the
element. This label is not visible.
How Has This Been Tested?
I used the browser's inspector (screenshots reflect that) to confirm
the presence of the a11y attributes and screen-reader-text elements on
both the add link and edit link forms.
The updates done in blocks/editable/format-toolbar.js were visible in
the add link / edit existing link workflow in the text block, just like
the screenshots show.
I wasn't able to figure out where is the
"blocks/library/button/index.js" actually used. It has in the edit
function a form with a class of editable-format-toolbar__link-modal,
just like the one generated with the insert/edit URL.
Locally only I tried adding an extra class on the
form.editable-format-toolbar__link-modal and trying to hunt it in the
browser, but I wasn't able to stumble upon it myself. That's why the
changes done on that file are minimal (added the button aria-label and
added a and added an ID to the URL input element itself,
without making use of withInstanceId - because there is no export
default I could add the withInstanceId call around).
Screenshots:
Add link form:
Edit link form:
Types of changes
New feature (non-breaking change which adds functionality).
Checklist: