diff --git a/.changeset/shaggy-phones-laugh.md b/.changeset/shaggy-phones-laugh.md new file mode 100644 index 0000000000..8cb711491b --- /dev/null +++ b/.changeset/shaggy-phones-laugh.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: disregard `popover` elements when determining whether an element has content diff --git a/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y/index.js b/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y/index.js index 50b107d068..f5f4982ed2 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y/index.js +++ b/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y/index.js @@ -824,6 +824,10 @@ function has_content(element) { } if (node.type === 'RegularElement' || node.type === 'SvelteElement') { + if (node.attributes.some((a) => a.type === 'Attribute' && a.name === 'popover')) { + continue; + } + if ( node.name === 'img' && node.attributes.some((node) => node.type === 'Attribute' && node.name === 'alt') diff --git a/packages/svelte/tests/validator/samples/a11y-popover-label/input.svelte b/packages/svelte/tests/validator/samples/a11y-popover-label/input.svelte new file mode 100644 index 0000000000..6fafa0a10c --- /dev/null +++ b/packages/svelte/tests/validator/samples/a11y-popover-label/input.svelte @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/packages/svelte/tests/validator/samples/a11y-popover-label/warnings.json b/packages/svelte/tests/validator/samples/a11y-popover-label/warnings.json new file mode 100644 index 0000000000..f5fd09c89d --- /dev/null +++ b/packages/svelte/tests/validator/samples/a11y-popover-label/warnings.json @@ -0,0 +1,14 @@ +[ + { + "code": "a11y_consider_explicit_label", + "message": "Buttons and links should either contain text or have an `aria-label`, `aria-labelledby` or `title` attribute", + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } +]