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

Commit 5a2ad02

Browse files
david-gangThomasBurleson
authored andcommitted
fix(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. fixes #6796. closes #7440.
1 parent 1c4814a commit 5a2ad02

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/components/icon/icon.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,15 @@ describe('mdIcon service', function() {
464464
});
465465
});
466466

467+
467468
function updateDefaults(svg) {
468469
svg = angular.element(svg)[0];
469470

471+
svg.removeAttribute('id');
472+
angular.forEach(svg.querySelectorAll('[id]'), function(item) {
473+
item.removeAttribute('id');
474+
});
475+
470476
angular.forEach({
471477
'xmlns' : 'http://www.w3.org/2000/svg',
472478
'fit' : '',

src/components/icon/js/iconService.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
* @param {string} id Icon name/id used to register the iconset
105105
* @param {string} url specifies the external location for the data file. Used internally by `$http` to load the
106106
* data or as part of the lookup in `$templateCache` if pre-loading was configured.
107-
* @param {number=} viewBoxSize Sets the width and height of the viewBox of all icons in the set.
107+
* @param {number=} viewBoxSize Sets the width and height of the viewBox of all icons in the set.
108108
* It is ignored for icons with an existing viewBox. All icons in the icon set should be the same size.
109109
* Default value is 24.
110110
*
@@ -134,7 +134,7 @@
134134
*
135135
* @param {string} url specifies the external location for the data file. Used internally by `$http` to load the
136136
* data or as part of the lookup in `$templateCache` if pre-loading was configured.
137-
* @param {number=} viewBoxSize Sets the width and height of the viewBox of all icons in the set.
137+
* @param {number=} viewBoxSize Sets the width and height of the viewBox of all icons in the set.
138138
* It is ignored for icons with an existing viewBox. All icons in the icon set should be the same size.
139139
* Default value is 24.
140140
*
@@ -247,7 +247,7 @@
247247
config.defaultViewBoxSize = viewBoxSize;
248248
return this;
249249
},
250-
250+
251251
/**
252252
* Register an alias name associated with a font-icon library style ;
253253
*/
@@ -422,8 +422,19 @@
422422
*/
423423
function cacheIcon( id ) {
424424

425-
return function updateCache( icon ) {
426-
iconCache[id] = isIcon(icon) ? icon : new Icon(icon, config[id]);
425+
return function updateCache( _icon ) {
426+
var icon = isIcon(_icon) ? _icon : new Icon(_icon, config[id]);
427+
428+
//clear id attributes to prevent aria issues
429+
var elem = icon.element;
430+
elem.removeAttribute('id');
431+
432+
angular.forEach(elem.querySelectorAll('[id]'), function(item) {
433+
item.removeAttribute('id');
434+
});
435+
436+
iconCache[id] = icon;
437+
427438

428439
return iconCache[id].clone();
429440
};

0 commit comments

Comments
 (0)