Skip to content

A platform for community discussion. Free, open, simple.

UX: set default dimensions on SVG icons (#37115)

Krisb117a894108c
diff --git a/frontend/discourse/app/lib/icon-library.js b/frontend/discourse/app/lib/icon-library.js
index f600bce5e71..3fc842c8712 100644
--- a/frontend/discourse/app/lib/icon-library.js
+++ b/frontend/discourse/app/lib/icon-library.js
@@ -165,7 +165,7 @@ registerIconRenderer({
string(icon, params) {
const id = escape(handleIconId(icon));
- let html = `<svg class='${escape(iconClasses(icon, params))} svg-string'`;
+ let html = `<svg class='${escape(iconClasses(icon, params))} svg-string' width='1em' height='1em'`;
if (params["aria-label"]) {
html += ` aria-hidden='false' aria-label='${escape(params["aria-label"])}'`;
@@ -205,6 +205,8 @@ registerIconRenderer({
const svgElement = document.createElementNS(SVG_NAMESPACE, "svg");
svgElement.setAttribute("class", classes);
+ svgElement.setAttribute("width", "1em");
+ svgElement.setAttribute("height", "1em");
svgElement.setAttribute("aria-hidden", true);
const useElement = document.createElementNS(SVG_NAMESPACE, "use");
diff --git a/frontend/discourse/tests/integration/components/prosemirror-editor/hashtag-test.js b/frontend/discourse/tests/integration/components/prosemirror-editor/hashtag-test.js
index 8793a4584de..83362f14754 100644
--- a/frontend/discourse/tests/integration/components/prosemirror-editor/hashtag-test.js
+++ b/frontend/discourse/tests/integration/components/prosemirror-editor/hashtag-test.js
@@ -76,7 +76,7 @@ module(
],
"with regular tags": [
"Hello #dev",
- '<p>Hello <a class="hashtag-cooked" data-name="dev" data-processed="true" contenteditable="false" draggable="true"><svg class="fa d-icon d-icon-tag svg-icon fa-width-auto hashtag-color--tag-1 svg-string" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><use href="#tag"></use></svg>dev</a></p>',
+ '<p>Hello <a class="hashtag-cooked" data-name="dev" data-processed="true" contenteditable="false" draggable="true"><svg class="fa d-icon d-icon-tag svg-icon fa-width-auto hashtag-color--tag-1 svg-string" width="1em" height="1em" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><use href="#tag"></use></svg>dev</a></p>',
"Hello #dev",
],
"hashtag with emoji": [
@@ -86,7 +86,7 @@ module(
],
"hashtag with icon": [
"Lets #discuss",
- '<p>Lets <a class="hashtag-cooked" data-name="discuss" data-processed="true" contenteditable="false" draggable="true"><span class="hashtag-category-icon hashtag-color--category-4"><svg class="fa d-icon d-icon-comment svg-icon fa-width-auto svg-string" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><use href="#comment"></use></svg></span>discuss</a></p>',
+ '<p>Lets <a class="hashtag-cooked" data-name="discuss" data-processed="true" contenteditable="false" draggable="true"><span class="hashtag-category-icon hashtag-color--category-4"><svg class="fa d-icon d-icon-comment svg-icon fa-width-auto svg-string" width="1em" height="1em" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><use href="#comment"></use></svg></span>discuss</a></p>',
"Lets #discuss",
],
"hashtag with emoji in text": [
diff --git a/frontend/discourse/tests/integration/helpers/d-icon-test.gjs b/frontend/discourse/tests/integration/helpers/d-icon-test.gjs
index 67b1b4316de..89ccd27be6f 100644
--- a/frontend/discourse/tests/integration/helpers/d-icon-test.gjs
+++ b/frontend/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 fa-width-auto svg-string" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><use href="#bars"></use></svg>'
+ '<svg class="fa d-icon d-icon-bars svg-icon fa-width-auto svg-string" width="1em" height="1em" 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 fa-width-auto svg-string" aria-hidden="true" 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 fa-width-auto svg-string" width="1em" height="1em" 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.js
index 920f44d4e85..d751a30a210 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 fa-width-auto svg-string' aria-hidden='true' 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 fa-width-auto svg-string' width='1em' height='1em' 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 fa-width-auto svg-string' aria-hidden='true' 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 fa-width-auto svg-string' width='1em' height='1em' 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 fa-width-auto svg-string' aria-hidden='true' 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 fa-width-auto svg-string' width='1em' height='1em' 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 fa-width-auto svg-string' aria-hidden='true' 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 fa-width-auto svg-string' width='1em' height='1em' 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 fa-width-auto svg-string' aria-hidden='true' 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 fa-width-auto svg-string' width='1em' height='1em' 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 fa-width-auto svg-string' aria-hidden='true' 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 fa-width-auto svg-string' width='1em' height='1em' 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 fa-width-auto svg-string' aria-hidden='true' 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 fa-width-auto svg-string' width='1em' height='1em' 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 fa-width-auto svg-string' aria-hidden='true' 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 fa-width-auto svg-string' width='1em' height='1em' aria-hidden='true' xmlns=\"http://www.w3.org/2000/svg\"><use href=\"#clock\" /></svg> 6:00 PM",
timezone: "UTC",
},
],