Implement accessibility defaults #150
Open
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.alttextparameter to thecreateBasefunction. If this argument is not provided, a warning will appear in the console. If it is provided,alttextwill be set as the text read aloud by a screen reader via anaria-describedbyattribute. The SVG will also be set to have an image role.addA11yAttributesthat takes inhtml(string) andalttext(string). The HTML string is expected to be ai2html output. The filter adds anaria-describedbyattribute to the ai2html wrapper and aroleattribute set toimg. The two artboards inside the wrapper are set toaria-hiddento prevent anything in the artboards (like axis labels) from being read.aria-descriptioninstead ofaria-describedbybut realized it was not working on iOS (i.e. no alt text was read aloud).graphicTitleexists, then thetitleof the graphic document is set tographicTitle. Otherwise, thetitleof the document is set to The Texas Tribune. In all practical cases,graphicTitleshould 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
createBaseor 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.iframebehavior.index.htmlfile which has aniframe, and atest.htmlfile which is ai2html output. It also contains two image files.npm run startand navigate to http://localhost:3000.Activating your screen reader
Testing
createBaseapp/templates/graphic.html. Copy the contents of that file and paste it intoapp/index.html.app/scripts/packs/graphic.js. ReplacerenderGraphicwith the following:alttextargument. 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/templatesand create a folder calledai2html-ouput. Inside this folder, place thetest.htmlfile from the zip file.app/assetsand 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
iframeGraphics on our website are embedded with an
iframeso it's important that the screen reader still works when the document is inside aniframe.index.htmlfile 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.srcattribute with the network URL.Note: it doesn't look like iOS Safari, iOS Chrome, or Windows reads the
iframetitle or embedded documenttitleif 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