Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's this PR do?
Essentially, this adds screen reader support for ai2html graphics and D3 graphics that use
createBase
.alttext
parameter to thecreateBase
function. If this argument is not provided, a warning will appear in the console. If it is provided,alttext
will be set as the text read aloud by a screen reader via anaria-describedby
attribute. The SVG will also be set to have an image role.addA11yAttributes
that takes inhtml
(string) andalttext
(string). The HTML string is expected to be ai2html output. The filter adds anaria-describedby
attribute to the ai2html wrapper and arole
attribute set toimg
. The two artboards inside the wrapper are set toaria-hidden
to prevent anything in the artboards (like axis labels) from being read.aria-description
instead ofaria-describedby
but realized it was not working on iOS (i.e. no alt text was read aloud).graphicTitle
exists, then thetitle
of the graphic document is set tographicTitle
. Otherwise, thetitle
of the document is set to The Texas Tribune. In all practical cases,graphicTitle
should probably be set.Why are we doing this? How does it help us?
Currently, screen readers do not read our graphics in a helpful way. This PR tries to fix that. We did have an alt text variable but it just wasn't used anywhere.
The main objective of this PR is to make sure that graphics generated with
createBase
or ai2html have only the headline, chatter, alt text, notes, source, and credit read aloud. Textual elements such as axis numbers or bar labels should not be read aloud in this implementation. There may be cases when we want those textual elements to be read out. In such cases, the kit user should make exceptions to these defaults by implementing some custom solution.How should this be manually tested?
There is a large matrix to test because I think operating systems and browsers in those operating systems all have slightly different screen reader behavior. MacOS (Chrome, Safari, Firefox), Windows (Chrome, Edge, Firefox), iOS, different Androids, etc.
Getting set up
npx github:texastribune/data-visuals-create#a11y graphic test-graphic
.iframe
behavior.index.html
file which has aniframe
, and atest.html
file which is ai2html output. It also contains two image files.npm run start
and navigate to http://localhost:3000.Activating your screen reader
Testing
createBase
app/templates/graphic.html
. Copy the contents of that file and paste it intoapp/index.html
.app/scripts/packs/graphic.js
. ReplacerenderGraphic
with the following:alttext
argument. Note that the numbers in the axes are no longer read aloud.Testing ai2html output
app/templates/graphic-static.html
. Copy the contents of that file and paste it intoapp/index.html
.app/templates
and create a folder calledai2html-ouput
. Inside this folder, place thetest.html
file from the zip file.app/assets
and create a folder calledimages
. Inside this folder, place the two image files from the zip file.{% set graphicAltText = context.alttext %}
(on line 19) with{% set graphicAltText = 'This is some alt text' %}
.{% set ai2html = "" %}
with{% set ai2html = "test" %}
.Testing inside an
iframe
Graphics on our website are embedded with an
iframe
so it's important that the screen reader still works when the document is inside aniframe
.index.html
file from the zip file in the root of the repository. If you have VSCode open, you can use the Live Server extension to serve this file. Otherwise, you can use Python by runningpython3 -m http.server
.src
attribute with the network URL.Note: it doesn't look like iOS Safari, iOS Chrome, or Windows reads the
iframe
title or embedded documenttitle
if they are set.How should this change be communicated to end users?
N/A
Are there any smells or added technical debt to note?
The ai2html nunjucks filter is pretty brittle — it relies on there only ever being two artboards with pixel sizes 664 and 360. It won't break anything if those sizes change, but we'll have to change the filter to get the properties to show up.
Are we using the right tags and attributes?
What are the relevant tickets?
N/A
Have you done the following, if applicable:
(optional: add explanation between parentheses)
TODOs / next steps:
CHANGELOG