Skip to content

Commit

Permalink
Do not use xlink:href in svg icons
Browse files Browse the repository at this point in the history
We can simply use href. The other is deprecated.
  • Loading branch information
tvdeyen committed Mar 13, 2024
1 parent 86a0be3 commit 5abc470
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/javascript/alchemy_admin/components/icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Icon extends HTMLElement {

render() {
const sizeClass = this.size ? ` icon--${this.size}` : ""
this.innerHTML = `<svg class="icon${sizeClass}"><use xlink:href="${this.spriteUrl}#ri-${this.iconName}${this.style}" /></svg>`
this.innerHTML = `<svg class="icon${sizeClass}"><use href="${this.spriteUrl}#ri-${this.iconName}${this.style}" /></svg>`
}

set name(value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
<% elsif navigation["inline_image"] %>
<%== navigation["inline_image"] %>
<% elsif navigation["icon"] %>
<%# Cannot use the render_icon helper, because the navigation["icon"] includes the style %>
<svg class="icon">
<use xlink:href="<%= asset_path("remixicon.symbol.svg") %>#ri-<%= navigation["icon"] %>" />
<use href="<%= asset_path("remixicon.symbol.svg") %>#ri-<%= navigation["icon"] %>" />
</svg>
<% else %>
<%= render_icon :table %>
Expand Down
8 changes: 4 additions & 4 deletions spec/javascript/alchemy_admin/components/icon.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("alchemy-icon", () => {
const icon = renderComponent("alchemy-icon", html)

expect(icon.innerHTML).toEqual(
'<svg class="icon"><use xlink:href="/assets/remixicon.symbol.svg#ri-image-line"></use></svg>'
'<svg class="icon"><use href="/assets/remixicon.symbol.svg#ri-image-line"></use></svg>'
)
})

Expand All @@ -22,7 +22,7 @@ describe("alchemy-icon", () => {
const icon = renderComponent("alchemy-icon", html)

expect(icon.innerHTML).toEqual(
'<svg class="icon"><use xlink:href="/assets/remixicon.symbol.svg#ri-image-fill"></use></svg>'
'<svg class="icon"><use href="/assets/remixicon.symbol.svg#ri-image-fill"></use></svg>'
)
})

Expand All @@ -34,7 +34,7 @@ describe("alchemy-icon", () => {
const icon = renderComponent("alchemy-icon", html)

expect(icon.innerHTML).toEqual(
'<svg class="icon"><use xlink:href="/assets/remixicon.symbol.svg#ri-image"></use></svg>'
'<svg class="icon"><use href="/assets/remixicon.symbol.svg#ri-image"></use></svg>'
)
})

Expand All @@ -46,7 +46,7 @@ describe("alchemy-icon", () => {
const icon = renderComponent("alchemy-icon", html)

expect(icon.innerHTML).toEqual(
'<svg class="icon icon--medium"><use xlink:href="/assets/remixicon.symbol.svg#ri-image-line"></use></svg>'
'<svg class="icon icon--medium"><use href="/assets/remixicon.symbol.svg#ri-image-line"></use></svg>'
)
})
})

0 comments on commit 5abc470

Please sign in to comment.