fix: treat `<img>` alt attribute as content for a11y labelling purposes (#13411)

fixes #13365
pull/13394/head
Rich Harris 2 months ago committed by GitHub
parent 276443fe5e
commit e3e8f22a6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: treat `<img>` alt attribute as content for a11y labelling purposes

@ -1161,6 +1161,13 @@ function has_content(element) {
} }
if (node.type === 'RegularElement' || node.type === 'SvelteElement') { 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)) { if (!has_content(node)) {
continue; continue;
} }

@ -9,3 +9,4 @@
<button>Click me</button> <button>Click me</button>
<a href="/#">Link text</a> <a href="/#">Link text</a>
<a href="/#"><img src="./icon.svg" alt="Link text"></a>

Loading…
Cancel
Save