Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Conversation

david-gang
Copy link
Contributor

fix(md-icon): accessibility issue with unique ids

When the same svg icon is placed multiple times in the same page, it raises an aria warning that every element should have an unique id.
The solution is to remove the id from the svg and the path children.

closes: #6796

@devversion devversion added the needs: review This PR is waiting on review from the team label Mar 7, 2016

for (var i=0; i<children.length;i++) {
var child = children[i];
if(child.nodeName==='path') {
Copy link
Member

Choose a reason for hiding this comment

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

Why only on the path node? circle etc, can also hold an id attribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. I will remove the if.

Copy link
Member

Choose a reason for hiding this comment

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

@david-gang I suggest, walking recursively through the children and remove the id if present.
Like so

(function recursiveIteration(element) {
  angular.forEach(element.childNodes, function(item) {
    item.removeAttribute('id');
    if (item.childNodes) {
      recursiveIteration(item)
    }
  });
})(myIconElement);

Or another way, would be the querySelector. Like so

angular.forEach(myIconElement.querySelectorAll('[id]'), function(item) {
  item.removeAttribute('id');
});

But I'm not sure what's the most elegant / performant solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@devversion The second option looks very nice. It should also be performant because it is a native function and the call stack is flat.

Copy link
Member

Choose a reason for hiding this comment

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

@david-gang Yes definitely, it looks more elegant, but I heard some negative about attribute selectors in IE and other browsers.

Copy link
Member

Choose a reason for hiding this comment

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

Just updated your test - now it works. See the results here: http://jsperf.com/recursive-iteration-vs-queryselectorall

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks 👍

Copy link
Member

Choose a reason for hiding this comment

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

No problem. Look here at IE11

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code is just called once per icon type, unconnected to the number of times i use the icon in the application, and even in ie11 the performance is 10^5 ops per second, so this should be fine.

Copy link
Member

Choose a reason for hiding this comment

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

It's okay 😄 Just wanted to share with you the performance differences.

We remove also recursively the descendants ids.
@david-gang david-gang deleted the david-gang-fix-aria-unique-ids-patch branch March 13, 2016 09:01
ThomasBurleson pushed a commit that referenced this pull request Apr 1, 2016
*  When the same svg icon is placed multiple times in the same page, it raises an aria warning that every element should have an unique id.

fixes #6796. closes #7440.
@Splaktar Splaktar removed the needs: review This PR is waiting on review from the team label Oct 23, 2018
@angular angular locked as resolved and limited conversation to collaborators Oct 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

md-icon / accesibility / validation usage with svg (i.e: https://www.google.com/design/icons/) duplicate id's issue
3 participants