Improve file block accessibility by adding aria-describedby to download button #28062
Conversation
@allilevine this looks great. Have there been any considerations for converting the [Download] button into a If the Download button were nested inside the link as a span, then you would only have one link. Thoughts? |
b404cec
to
7a38587
I haven't seen any mention of combining the two links, thanks for pointing that out! Is the advantage that only one link would be read by screen readers, instead of two of the same link? I made the change in save.js and tried it out with VoiceOver:
One potential issue I see is that if there's no |
@enriquesanchez or @afercia would you mind weighing in on the accessibility of two links vs. one link? |
@allilevine yes, that's what I was thinking of. Having a duplicate link means more to wade through for screen readers and just for tabbing (although the effect on tabbing is not quite as annoying). But the potential issue you bring up is a good one. Could you do the following, only wrapping the
|
That could work! Then the Download button would still show up without the That scenario isn't ideal for accessibility though, since we lose the description of the file that the button downloads again. |
The two links have different functions: the first opens the file in the browser, and the second downloads it, so we shouldn't try to mash them together. |
beda8f2
to
c2811c8
Since 29 files is a lot, I've added some comments to clarify what's happening in the code.
Any changes in packages/e2e-tests/fixtures
are required updates to the fixture tests, many of which are auto-generated.
@@ -9,6 +9,12 @@ | |||
"href": { | |||
"type": "string" | |||
}, | |||
"fileId": { |
This change adds fileId
as a block attribute, so that we can always identify the right file name to announce.
import { RichText } from '@wordpress/block-editor'; | ||
|
||
// Version of the file block without PR#28062 accessibility fix. | ||
const deprecated = [ |
We're making changes to how the block is edited and saved, so we need to deprecate the previous version of the block. That way, it will still be supported in older posts.
@@ -49,7 +49,13 @@ function ClipboardToolbarButton( { text, disabled } ) { | |||
); | |||
} | |||
|
|||
function FileEdit( { attributes, setAttributes, noticeUI, noticeOperations } ) { | |||
function FileEdit( { |
We're just adding clientId
here, to use it in the fileId
.
@@ -93,6 +99,11 @@ function FileEdit( { attributes, setAttributes, noticeUI, noticeOperations } ) { | |||
} | |||
}, [] ); | |||
|
|||
useEffect( () => { |
Whenever the clientId
changes, the fileId
changes. That way it's always unique, even if we duplicate the block.
@@ -7,6 +7,7 @@ import { file as icon } from '@wordpress/icons'; | |||
/** | |||
* Internal dependencies | |||
*/ | |||
import deprecated from './deprecated'; |
Here we're telling the block about the deprecated version.
@@ -30,6 +32,7 @@ export default function save( { attributes } ) { | |||
href={ href } | |||
className="wp-block-file__button" | |||
download={ true } | |||
aria-describedby={ fileId } |
This is the main event! We're adding an aria-describedby
prop to the Download button that references the file link above. That's how the Download button announces the file name from the link.
d493e87
to
09d17fd
@sarahricker @joedolson Can you review this PR from an a11y perspective? Is it still a change we want to make? |
I think this change would still be helpful but how stale is the code now? Most of this have to be reworked? |
@alexstine I'm happy to refactor if you see value in making this change. It was just missing an accessibility review. |
I'm perfectly happy to do the review once it is fixed up. Sadly the Accessibility team is quite small so while I probably browsed over the related issue, I never took much of a close look. Best way to get my attention is to flag me down in Make WordPress Slack. Thanks. |
09d17fd
to
eb4ffca
eb4ffca
to
187f89a
40964dd
to
8b6a49e
@alexstine Good to know, thanks! I've updated the PR. I did notice that the PDF preview feature that was added to the file block in the meantime uses |
@allilevine I'll try to review this today but I may run out of time. Adding it to the Accessibility team meeting agenda in case someone else can get to it first. |
@allilevine Changes from A11Y perspective are perfect. Nice one.
Thank you! |
@talldan It would be great to get your review of these changes, especially to make sure they address your feedback here. |
This is working well! Thanks for fixing the issue. Also, great work on the PR description and explanatory comments
allilevine commentedJan 8, 2021
•
edited
Description
This PR adds an id to the file link and adds that id as an
aria-describedby
on the download button. This announces the Download button in screen readers as "Download, [content from the file link text]".For example, in this gif with "captions-1" as the link text, it announces the Download button as "Download, captions-1."
To avoid duplicate ids (and the potential for the wrong file name being linked to the download button), I used the
clientId
method suggested here.Fixes #22908
Updates #22914
How has this been tested?
git fetch origin pull/28062/head:pr/28062 && git checkout pr/28062
Types of changes
This change fixes an accessibility issue, and requires a deprecation entry and new fixtures.
Checklist:
The text was updated successfully, but these errors were encountered: