Skip to content

Commit

Permalink
feat(a11y): add titles
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfbecker committed Nov 15, 2020
1 parent 9ab65f1 commit becf341
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 31 deletions.
9 changes: 8 additions & 1 deletion src/element.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { svgNamespace, isHTMLAnchorElement, isHTMLImageElement, isHTMLInputElement } from './dom'
import { svgNamespace, isHTMLAnchorElement, isHTMLImageElement, isHTMLInputElement, isHTMLElement } from './dom'
import { getAccessibilityAttributes } from './accessibility'
import { TraversalContext, walkNode } from './traversal'
import {
Expand Down Expand Up @@ -51,6 +51,13 @@ export function handleElement(element: Element, context: Readonly<TraversalConte
svgContainer.setAttribute('class', className)
}

// Title
if (isHTMLElement(element) && element.title) {
const svgTitle = context.svgDocument.createElementNS(svgNamespace, 'title')
svgTitle.textContent = element.title
svgContainer.prepend(svgTitle)
}

// Which parent should the container itself be appended to?
const stackingLayerName = determineStackingLayer(styles, parentStyles)
const stackingLayer = stackingLayerName
Expand Down
58 changes: 29 additions & 29 deletions src/test/snapshots/https%3A%2F%2Fnews.ycombinator.com%2F.a11y.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -128,7 +128,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -184,7 +184,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -240,7 +240,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -296,7 +296,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -352,7 +352,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -408,7 +408,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -464,7 +464,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -520,7 +520,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -576,7 +576,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -632,7 +632,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -688,7 +688,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -776,7 +776,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -832,7 +832,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -888,7 +888,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -944,7 +944,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -1000,7 +1000,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -1056,7 +1056,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -1112,7 +1112,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -1168,7 +1168,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -1224,7 +1224,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -1280,7 +1280,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -1336,7 +1336,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -1392,7 +1392,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -1448,7 +1448,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -1504,7 +1504,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -1560,7 +1560,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -1616,7 +1616,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down Expand Up @@ -1672,7 +1672,7 @@
},
{
"role": "link",
"name": ""
"name": "upvote"
},
{
"role": "link",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
{
"role": "button",
"name": ""
"name": "Google apps"
},
{
"role": "link",
Expand Down

0 comments on commit becf341

Please sign in to comment.