mirror of
https://github.com/discourse/discourse.git
synced 2025-06-24 16:57:24 +08:00
A11Y: SVG icons should be hidden unless a label is provided (#33059)
This is fairly minor because usually SVGs aren't focusable, but this adds `aria-hidden='true'` to all SVGs by default unless either an `aria-label` or `label` is provided. This gets reported to us in automated tests from time to time. So now: 1. SVG: `aria-hidden="true"` (new behavior, safe default when no label is provided) 2. SVG with `label` param: `aria-hidden="true"` and `sr-only` label is provided 3. SVG with `aria-label` param: `aria-hidden="false"` and `aria-label` is provided
This commit is contained in:
@ -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) {
|
||||
|
@ -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>'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@ -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",
|
||||
},
|
||||
],
|
||||
|
Reference in New Issue
Block a user