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

Improve file block accessibility by adding aria-describedby to download button #28062

Merged
merged 9 commits into from Sep 17, 2021

Conversation

@allilevine
Copy link
Contributor

@allilevine allilevine commented Jan 8, 2021

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]".

fileblock

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?

  1. Checkout this PR: git fetch origin pull/28062/head:pr/28062 && git checkout pr/28062
  2. Add a new file block to a post:

Screen Shot 2021-03-17 at 5 59 01 PM

  1. Upload a file and publish or preview the post.
  2. Navigate the post with a screen reader. The Download button should be announced as "Download," then the file name.

Types of changes

This change fixes an accessibility issue, and requires a deprecation entry and new fixtures.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • 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.
@allilevine allilevine changed the title File Block: Semantically link the filename link to the download button on the file block. [WIP] File Block: Semantically link the filename link to the download button on the file block. Jan 8, 2021
@allilevine allilevine changed the title [WIP] File Block: Semantically link the filename link to the download button on the file block. File Block: Semantically link the filename link to the download button on the file block. Jan 8, 2021
@allilevine allilevine marked this pull request as ready for review Jan 8, 2021
@eyesofjeremy
Copy link

@eyesofjeremy eyesofjeremy commented Feb 23, 2021

@allilevine this looks great. Have there been any considerations for converting the [Download] button into a span element? I found this PR while reviewing a site for accessibility, and have similar concerns. Adding a label to the button fixes one of them, but we still end up with an extra unnecessary link.

If the Download button were nested inside the link as a span, then you would only have one link. Thoughts?

@allilevine allilevine force-pushed the update/file-block-describedby branch from b404cec to 7a38587 Feb 26, 2021
@allilevine
Copy link
Contributor Author

@allilevine allilevine commented Feb 26, 2021

@allilevine this looks great. Have there been any considerations for converting the [Download] button into a span element? I found this PR while reviewing a site for accessibility, and have similar concerns. Adding a label to the button fixes one of them, but we still end up with an extra unnecessary link.

If the Download button were nested inside the link as a span, then you would only have one link. Thoughts?

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:

{ ! RichText.isEmpty( fileName ) && (
	<a
		href={ textLinkHref }
		target={ textLinkTarget }
		rel={ textLinkTarget ? 'noreferrer noopener' : false }
	>
	<RichText.Content value={ fileName } />

	{ showDownloadButton && (
		<span className="wp-block-file__button">
			<RichText.Content
				value={ downloadButtonText }
			/>
		</span>
	) }
	</a>
) }

fileblockwithspan

One potential issue I see is that if there's no fileName, nothing will display, whereas before the Download button would still display. But it does eliminate the need for a unique block id.

@allilevine
Copy link
Contributor Author

@allilevine allilevine commented Feb 26, 2021

@enriquesanchez or @afercia would you mind weighing in on the accessibility of two links vs. one link?

@eyesofjeremy
Copy link

@eyesofjeremy eyesofjeremy commented Feb 26, 2021

Is the advantage that only one link would be read by screen readers, instead of two of the same 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 RichText.Content in the conditional for filename? (Note:, haven't tested)

               <a
                    href={ textLinkHref }
                    target={ textLinkTarget }
                    rel={ textLinkTarget ? 'noreferrer noopener' : false }
                >
                    { ! RichText.isEmpty( fileName ) && (
                    <RichText.Content value={ fileName } />
                    ) }

                    { showDownloadButton && (
                        <span className="wp-block-file__button">
                            <RichText.Content
                                value={ downloadButtonText }
                            />
                        </span>
                    ) }
                </a>

Base automatically changed from master to trunk Mar 1, 2021
@allilevine
Copy link
Contributor Author

@allilevine allilevine commented Mar 2, 2021

Could you do the following, only wrapping the RichText.Content in the conditional for filename? (Note:, haven't tested)

That could work! Then the Download button would still show up without the fileName, which is the current behavior.

That scenario isn't ideal for accessibility though, since we lose the description of the file that the button downloads again. 😕 Maybe it would help to look at why and when that could happen.

@tellthemachines
Copy link
Contributor

@tellthemachines tellthemachines commented Mar 3, 2021

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.

@allilevine allilevine force-pushed the update/file-block-describedby branch 2 times, most recently from beda8f2 to c2811c8 Mar 12, 2021
@allilevine allilevine changed the title File Block: Semantically link the filename link to the download button on the file block. Improve file block download button accessibility Mar 17, 2021
Copy link
Contributor Author

@allilevine allilevine left a comment

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": {
Copy link
Contributor Author

@allilevine allilevine Mar 17, 2021

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 = [
Copy link
Contributor Author

@allilevine allilevine Mar 17, 2021

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( {
Copy link
Contributor Author

@allilevine allilevine Mar 17, 2021

We're just adding clientId here, to use it in the fileId.

@@ -93,6 +99,11 @@ function FileEdit( { attributes, setAttributes, noticeUI, noticeOperations } ) {
}
}, [] );

useEffect( () => {
Copy link
Contributor Author

@allilevine allilevine Mar 17, 2021

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';
Copy link
Contributor Author

@allilevine allilevine Mar 17, 2021

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 }
Copy link
Contributor Author

@allilevine allilevine Mar 17, 2021

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.

@allilevine allilevine force-pushed the update/file-block-describedby branch 3 times, most recently from d493e87 to 09d17fd Apr 15, 2021
@allilevine
Copy link
Contributor Author

@allilevine allilevine commented Apr 15, 2021

@sarahricker @joedolson Can you review this PR from an a11y perspective? Is it still a change we want to make?

@alexstine
Copy link
Contributor

@alexstine alexstine commented Aug 26, 2021

I think this change would still be helpful but how stale is the code now? Most of this have to be reworked?

@allilevine
Copy link
Contributor Author

@allilevine allilevine commented Aug 27, 2021

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.

@alexstine
Copy link
Contributor

@alexstine alexstine commented Aug 27, 2021

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.

@allilevine allilevine force-pushed the update/file-block-describedby branch from 09d17fd to eb4ffca Aug 27, 2021
@allilevine allilevine changed the title Improve file block download button accessibility [WIP] Improve file block download button accessibility Aug 27, 2021
@allilevine allilevine force-pushed the update/file-block-describedby branch from eb4ffca to 187f89a Aug 31, 2021
@allilevine allilevine force-pushed the update/file-block-describedby branch from 40964dd to 8b6a49e Sep 1, 2021
@allilevine allilevine changed the title [WIP] Improve file block download button accessibility Improve file block download button accessibility Sep 2, 2021
@allilevine
Copy link
Contributor Author

@allilevine allilevine commented Sep 2, 2021

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.

@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 aria-label. That would be a simpler change to make to add the fileName to the Download button, but maybe not as much of an improvement. It seems to replace the "Download" text.

@alexstine
Copy link
Contributor

@alexstine alexstine commented Sep 3, 2021

@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.

Copy link
Contributor

@alexstine alexstine left a comment

@allilevine Changes from A11Y perspective are perfect. Nice one. 👍

@allilevine
Copy link
Contributor Author

@allilevine allilevine commented Sep 14, 2021

@allilevine Changes from A11Y perspective are perfect. Nice one. 👍

Thank you! 🙌

@allilevine
Copy link
Contributor Author

@allilevine allilevine commented Sep 15, 2021

@talldan It would be great to get your review of these changes, especially to make sure they address your feedback here.

Copy link
Contributor

@tellthemachines tellthemachines left a comment

This is working well! Thanks for fixing the issue. Also, great work on the PR description and explanatory comments

@allilevine allilevine added this to the Gutenberg 11.6 milestone Sep 17, 2021
@allilevine allilevine changed the title Improve file block download button accessibility Improve file block accessibility by adding aria-describedby to download button Sep 17, 2021
@allilevine allilevine merged commit aa6217f into WordPress:trunk Sep 17, 2021
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

5 participants