A platform for community discussion. Free, open, simple.
A11Y: SVG icons should be hidden unless a label is provided (#33059)
Krisf66339338ee6
diff --git a/app/assets/javascripts/discourse/app/lib/icon-library.js b/app/assets/javascripts/discourse/app/lib/icon-library.jsindex bedffebeca4..a6011dbee49 100644--- a/app/assets/javascripts/discourse/app/lib/icon-library.js+++ b/app/assets/javascripts/discourse/app/lib/icon-library.js@@ -156,12 +156,10 @@ registerIconRenderer({const id = escape(handleIconId(icon));let html = `<svg class='${escape(iconClasses(icon, params))} svg-string'`;- if (params.label) {+ if (params["aria-label"]) {+ html += ` aria-hidden='false' aria-label='${escape(params["aria-label"])}'`;+ } else {html += " aria-hidden='true'";- } else if (params["aria-label"]) {- html += ` aria-hidden='false' aria-label='${escape(- params["aria-label"]- )}'`;}html += ` xmlns="${SVG_NAMESPACE}"><use href="#${id}" /></svg>`;if (params.label) {diff --git a/app/assets/javascripts/discourse/tests/integration/helpers/d-icon-test.gjs b/app/assets/javascripts/discourse/tests/integration/helpers/d-icon-test.gjsindex 4fea84f1842..456e9976899 100644--- a/app/assets/javascripts/discourse/tests/integration/helpers/d-icon-test.gjs+++ b/app/assets/javascripts/discourse/tests/integration/helpers/d-icon-test.gjs@@ -16,7 +16,7 @@ module("Integration | Helper | d-icon", function (hooks) {assert.dom(".test").hasHtml(- '<svg class="fa d-icon d-icon-bars svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#bars"></use></svg>'+ '<svg class="fa d-icon d-icon-bars svg-icon svg-string" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><use href="#bars"></use></svg>');});@@ -30,7 +30,7 @@ module("Integration | Helper | d-icon", function (hooks) {assert.dom(".test").hasHtml(- '<svg class="fa d-icon d-icon-d-watching svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#discourse-bell-exclamation"></use></svg>'+ '<svg class="fa d-icon d-icon-d-watching svg-icon svg-string" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><use href="#discourse-bell-exclamation"></use></svg>');});});diff --git a/plugins/discourse-local-dates/test/javascripts/unit/local-date-builder-test.js b/plugins/discourse-local-dates/test/javascripts/unit/local-date-builder-test.jsindex 6a0827c7693..471c8cf0ac5 100644--- a/plugins/discourse-local-dates/test/javascripts/unit/local-date-builder-test.js+++ b/plugins/discourse-local-dates/test/javascripts/unit/local-date-builder-test.js@@ -467,7 +467,7 @@ module("Unit | Library | local-date-builder", function () {{current: true,formatted:- 'Sunday, March 22, 2020 <br /><svg class=\'fa d-icon d-icon-clock svg-icon svg-string\' xmlns="http://www.w3.org/2000/svg"><use href="#clock" /></svg> 12:00 AM → 1:30 AM',+ "Sunday, March 22, 2020 <br /><svg class='fa d-icon d-icon-clock svg-icon svg-string' aria-hidden='true' xmlns=\"http://www.w3.org/2000/svg\"><use href=\"#clock\" /></svg> 12:00 AM → 1:30 AM",timezone: "Paris",},],@@ -499,7 +499,7 @@ module("Unit | Library | local-date-builder", function () {{current: true,formatted:- 'Sunday, March 22, 2020 <br /><svg class=\'fa d-icon d-icon-clock svg-icon svg-string\' xmlns="http://www.w3.org/2000/svg"><use href="#clock" /></svg> 11:34 AM',+ "Sunday, March 22, 2020 <br /><svg class='fa d-icon d-icon-clock svg-icon svg-string' aria-hidden='true' xmlns=\"http://www.w3.org/2000/svg\"><use href=\"#clock\" /></svg> 11:34 AM",timezone: "Paris",},],@@ -555,22 +555,22 @@ module("Unit | Library | local-date-builder", function () {{current: true,formatted:- 'Tuesday, April 7, 2020 <br /><svg class=\'fa d-icon d-icon-clock svg-icon svg-string\' xmlns="http://www.w3.org/2000/svg"><use href="#clock" /></svg> 2:54 PM',+ "Tuesday, April 7, 2020 <br /><svg class='fa d-icon d-icon-clock svg-icon svg-string' aria-hidden='true' xmlns=\"http://www.w3.org/2000/svg\"><use href=\"#clock\" /></svg> 2:54 PM",timezone: "Paris",},{formatted:- 'Tuesday, April 7, 2020 <br /><svg class=\'fa d-icon d-icon-clock svg-icon svg-string\' xmlns="http://www.w3.org/2000/svg"><use href="#clock" /></svg> 1:54 PM',+ "Tuesday, April 7, 2020 <br /><svg class='fa d-icon d-icon-clock svg-icon svg-string' aria-hidden='true' xmlns=\"http://www.w3.org/2000/svg\"><use href=\"#clock\" /></svg> 1:54 PM",timezone: "London",},{formatted:- 'Tuesday, April 7, 2020 <br /><svg class=\'fa d-icon d-icon-clock svg-icon svg-string\' xmlns="http://www.w3.org/2000/svg"><use href="#clock" /></svg> 1:54 PM',+ "Tuesday, April 7, 2020 <br /><svg class='fa d-icon d-icon-clock svg-icon svg-string' aria-hidden='true' xmlns=\"http://www.w3.org/2000/svg\"><use href=\"#clock\" /></svg> 1:54 PM",timezone: "Lagos",},{formatted:- 'Tuesday, April 7, 2020 <br /><svg class=\'fa d-icon d-icon-clock svg-icon svg-string\' xmlns="http://www.w3.org/2000/svg"><use href="#clock" /></svg> 10:54 PM',+ "Tuesday, April 7, 2020 <br /><svg class='fa d-icon d-icon-clock svg-icon svg-string' aria-hidden='true' xmlns=\"http://www.w3.org/2000/svg\"><use href=\"#clock\" /></svg> 10:54 PM",timezone: "Sydney",},],@@ -590,12 +590,12 @@ module("Unit | Library | local-date-builder", function () {{current: true,formatted:- 'Wednesday, May 13, 2020 <br /><svg class=\'fa d-icon d-icon-clock svg-icon svg-string\' xmlns="http://www.w3.org/2000/svg"><use href="#clock" /></svg> 11:00 AM',+ "Wednesday, May 13, 2020 <br /><svg class='fa d-icon d-icon-clock svg-icon svg-string' aria-hidden='true' xmlns=\"http://www.w3.org/2000/svg\"><use href=\"#clock\" /></svg> 11:00 AM",timezone: "Los Angeles",},{formatted:- 'Wednesday, May 13, 2020 <br /><svg class=\'fa d-icon d-icon-clock svg-icon svg-string\' xmlns="http://www.w3.org/2000/svg"><use href="#clock" /></svg> 6:00 PM',+ "Wednesday, May 13, 2020 <br /><svg class='fa d-icon d-icon-clock svg-icon svg-string' aria-hidden='true' xmlns=\"http://www.w3.org/2000/svg\"><use href=\"#clock\" /></svg> 6:00 PM",timezone: "UTC",},],