diff --git a/.changeset/nervous-chefs-exist.md b/.changeset/nervous-chefs-exist.md new file mode 100644 index 0000000000..c73b9818c3 --- /dev/null +++ b/.changeset/nervous-chefs-exist.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: treat `` alt attribute as content for a11y labelling purposes diff --git a/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y.js b/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y.js index 4e919e81d1..9fddade24d 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y.js +++ b/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y.js @@ -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; } diff --git a/packages/svelte/tests/validator/samples/a11y-consider-explicit-label/input.svelte b/packages/svelte/tests/validator/samples/a11y-consider-explicit-label/input.svelte index 6c5a35fc39..11dc007352 100644 --- a/packages/svelte/tests/validator/samples/a11y-consider-explicit-label/input.svelte +++ b/packages/svelte/tests/validator/samples/a11y-consider-explicit-label/input.svelte @@ -9,3 +9,4 @@ Link text +Link text