Skip to content

Commit

Permalink
fix: treat <img> alt attribute as content for a11y labelling purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Sep 27, 2024
1 parent 505e8ca commit d5424c6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-chefs-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: treat `<img>` alt attribute as content for a11y labelling purposes
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,13 @@ function has_content(element) {
}

if (node.type === 'RegularElement' || node.type === 'SvelteElement') {
if (
node.name === 'img' &&
node.attributes.some((node) => node.type === 'Attribute' && node.name === 'alt')
) {
return true;
}

if (!has_content(node)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@

<button>Click me</button>
<a href="/#">Link text</a>
<a href="/#"><img src="./icon.svg" alt="Link text"></a>

0 comments on commit d5424c6

Please sign in to comment.