10 * The URL of an image for the icon. If the src property is specified,
11 * the icon property should not be.
20 * Specifies the icon name or index in the set of icons available in
21 * the icon's icon set. If the icon property is specified,
22 * the src property should not be.
31 * Alternative text content for accessibility support.
32 * If alt is present and not empty, it will set the element's role to img and add an aria-label whose content matches alt.
33 * If alt is present and is an empty string, '', it will hide the element from the accessibility layer
34 * If alt is not present, it will set the element's role to img and the element will fallback to using the icon attribute for its aria-label.
47 defaultIconset: 'icons',
51 meta = document.createElement('core-iconset');
54 // Allow user-provided `aria-label` in preference to any other text alternative.
55 if (this.hasAttribute('aria-label')) {
56 // Set `role` if it has not been overridden.
57 if (!this.hasAttribute('role')) {
58 this.setAttribute('role', 'img');
65 srcChanged: function() {
66 var icon = this._icon || document.createElement('div');
67 icon.textContent = '';
68 icon.setAttribute('fit', '');
69 icon.style.backgroundImage = 'url(' + this.src + ')';
70 icon.style.backgroundPosition = 'center';
71 icon.style.backgroundSize = '100%';
72 if (!icon.parentNode) {
73 this.appendChild(icon);
78 getIconset: function(name) {
79 return meta.byId(name || this.defaultIconset);
82 updateIcon: function(oldVal, newVal) {
87 var parts = String(this.icon).split(':');
88 var icon = parts.pop();
90 var set = this.getIconset(parts.pop());
92 this._icon = set.applyIcon(this, icon);
94 this._icon.setAttribute('fit', '');
98 // Check to see if we're using the old icon's name for our a11y fallback
100 if (oldVal.split(':').pop() == this.getAttribute('aria-label')) {
106 updateAlt: function() {
107 // Respect the user's decision to remove this element from
109 if (this.getAttribute('aria-hidden')) {
113 // Remove element from a11y tree if `alt` is empty, otherwise
114 // use `alt` as `aria-label`.
115 if (this.alt === '') {
116 this.setAttribute('aria-hidden', 'true');
117 if (this.hasAttribute('role')) {
118 this.removeAttribute('role');
120 if (this.hasAttribute('aria-label')) {
121 this.removeAttribute('aria-label');
124 this.setAttribute('aria-label', this.alt ||
125 this.icon.split(':').pop());
126 if (!this.hasAttribute('role')) {
127 this.setAttribute('role', 'img');
129 if (this.hasAttribute('aria-hidden')) {
130 this.removeAttribute('aria-hidden');