Skip to content
Snippets Groups Projects
Commit 803bea12 authored by Yan, Andrew N.'s avatar Yan, Andrew N.
Browse files

Merge branch 'master' of github.com:usgs/waterdataui into wdfn-62-masking-qualifiers

parents 17f6a6fa 3d21b3ac
No related branches found
No related tags found
No related merge requests found
...@@ -7,9 +7,13 @@ ...@@ -7,9 +7,13 @@
* @param {Boolean} isInteractive * @param {Boolean} isInteractive
*/ */
function addSVGAccessibility(svg, {title, description, isInteractive}) { function addSVGAccessibility(svg, {title, description, isInteractive}) {
svg.attr('title', title) svg.selectAll('title, desc').remove();
.attr('desc', description)
.attr('aria-labelledby', 'title desc'); svg.insert('desc', ':first-child')
.html(description);
svg.insert('title', ':first-child')
.html(title);
svg.attr('aria-labelledby', 'title desc');
if (isInteractive) { if (isInteractive) {
svg.attr('tabindex', 0); svg.attr('tabindex', 0);
} }
......
...@@ -13,20 +13,47 @@ describe('svgAccessibility tests', () => { ...@@ -13,20 +13,47 @@ describe('svgAccessibility tests', () => {
svg.remove(); svg.remove();
}); });
it('Should add a title, desc, and aria attributes', () => { it('Should add a title and desc tags and aria attributes', () => {
addSVGAccessibility(svg, { addSVGAccessibility(svg, {
title: 'This is a title', title: 'This is a title',
description: 'This is a description', description: 'This is a description',
isInteractive: false isInteractive: false
}); });
expect(svg.attr('title')).toBe('This is a title'); const title = svg.selectAll('title');
expect(svg.attr('desc')).toBe('This is a description'); const desc = svg.selectAll('desc');
expect(title.size()).toBe(1);
expect(desc.size()).toBe(1);
expect(title.html()).toEqual('This is a title');
expect(desc.html()).toEqual('This is a description');
const labelledBy = svg.attr('aria-labelledby'); const labelledBy = svg.attr('aria-labelledby');
expect(labelledBy).toContain('title'); expect(labelledBy).toContain('title');
expect(labelledBy).toContain('desc'); expect(labelledBy).toContain('desc');
}); });
it('Should remove the previous title and desc tags when called again', () => {
addSVGAccessibility(svg, {
title: 'This is a title',
description: 'This is a description',
isInteractive: false
});
addSVGAccessibility(svg, {
title: 'That is a title',
description: 'That is a description',
isInteractive: false
});
const title = svg.selectAll('title');
const desc = svg.selectAll('desc');
expect(title.size()).toBe(1);
expect(desc.size()).toBe(1);
expect(title.html()).toEqual('That is a title');
expect(desc.html()).toEqual('That is a description');
});
it('Should not add a tabindex if isInteractive is false', () => { it('Should not add a tabindex if isInteractive is false', () => {
addSVGAccessibility(svg, { addSVGAccessibility(svg, {
title: 'This is a title', title: 'This is a title',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment