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

Add alt tags to images for a11y #529

Merged
merged 1 commit into from
Apr 8, 2018

Conversation

amyrlam
Copy link
Contributor

@amyrlam amyrlam commented Apr 6, 2018

Motivation

Have you read the Contributing Guidelines on pull requests?

yes

Test Plan

Ran pa11y http://localhost:3000/ and confirmed no results for Error: Img element missing an alt attribute. Use the alt attribute to specify a short text alternative from the original gist.

Related PRs

N/A

Details

  • Add imageAlt to GridBlock
  • Set alt equal to user.caption for mapped users
  • Set alt equal to post.author for blog posts
  • Update documentation

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Apr 6, 2018
@amyrlam
Copy link
Contributor Author

amyrlam commented Apr 6, 2018

👋@yangshun let me know if I should make any edits!

Copy link
Contributor

@JoelMarcey JoelMarcey left a comment

Choose a reason for hiding this comment

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

Thanks for doing this!

Also, do any CSS updates in main.css need to be done for this? In the gridBlock.blockImage section, for example. Maybe not, but just making sure.

@@ -64,6 +64,7 @@ The `contents` attribute is an array containing the contents of each section of
- `imageAlign` field for image alignment relative to the text, which defaults to `top` and can be set to `bottom`, `left`, or `right`
- `title` for the title to display for this section, which is parsed from markdown
- `imageLink` for a link destination from clicking the image
- `imageAlt` provides an alt tag for an image for a11y
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe

  • imageAlt for the description of what text will be shown in case the image is not available

instead?

if (image) {
if (imageLink) {
return (
<div className="blockImage">
<a href={imageLink}>
<img src={image} />
<img src={image} alt={imageAlt} />
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we do a check here in case imageAlt isn't provided?

like

<img src={image} alt={imageAlt ? imageAlt : ''}

or something like that?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's fine as-is because React does not render any props that are undefined or null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Yeah I didn't add the check, because without an imageAlt, the alt didn't show up on inspection in the browser. Thanks @yangshun for explaining why!

</a>
</div>
);
} else {
return (
<div className="blockImage">
<img src={image} />
<img src={image} alt={imageAlt} />
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From #529 (comment), leave as-is.

Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

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

Great work @amyrlam ! LGTM once the comments are responded to. Will leave it to @JoelMarcey to give the final approval and merging.

if (image) {
if (imageLink) {
return (
<div className="blockImage">
<a href={imageLink}>
<img src={image} />
<img src={image} alt={imageAlt} />
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's fine as-is because React does not render any props that are undefined or null.

@@ -5,7 +5,7 @@ authorURL: http://twitter.com/JoelMarcey
authorFBID: 611217057
---

![](/img/slash-introducing.png)
![introducing Slash](/img/slash-introducing.png)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit - Title case - "Introducing Slash"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Sorry, had done that intentionally thinking it was the alt standard. I changed some other ones too to Title Case.

@@ -24,7 +24,7 @@ Docusaurus also provides core website and documentation features out-of-the-box

## The Birth of docusaurus

![](/img/slash-birth.png)
![birth of Slash](/img/slash-birth.png)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit - Title case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

<p>
Slash is the official mascot of Docusaurus. You will find different variations of her throughout the <a href="https://docusaurus.io">website</a>, whether she is moving fast on her scooter or writing documentation at her standing desk. At Facebook, we have actual Slash plushies -- and you never know, you may see these plushies at various events and conferences in the future.
</p>
</Container>
<Container className="mainContainer">
<h2>Birth of Slash</h2>
<img src={`${siteConfig.baseUrl}img/slash-birth.png`} />
<img src={`${siteConfig.baseUrl}img/slash-birth.png`} alt="birth of Slash"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit - Title case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@amyrlam amyrlam force-pushed the amyrlam/a11y-alt-tag branch 2 times, most recently from d437fd9 to 038e6fa Compare April 7, 2018 21:00
- Add imageAlt to GridBlock
- Set alt equal to `user.caption` for mapped users
- Set alt equal to `post.author` for blog posts
- Update documentation
@amyrlam
Copy link
Contributor Author

amyrlam commented Apr 7, 2018

Made edits and squashed them in, wondering if you prefer squashing or a separate commit?

I don't think any CSS changes are needed for the alt tag, since it's for if the images cannot be displayed.

Let me know if other edits needed and thanks for the feedback @JoelMarcey @yangshun!

@yangshun
Copy link
Contributor

yangshun commented Apr 7, 2018 via email

@amyrlam
Copy link
Contributor Author

amyrlam commented Apr 8, 2018

Thanks - good to know about the squash option for next time!

Copy link
Contributor

@JoelMarcey JoelMarcey left a comment

Choose a reason for hiding this comment

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

Let's ship it!

@JoelMarcey JoelMarcey merged commit c2cd169 into facebook:master Apr 8, 2018
@amyrlam amyrlam deleted the amyrlam/a11y-alt-tag branch May 11, 2018 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants