diff --git a/.changeset/shaggy-phones-laugh.md b/.changeset/shaggy-phones-laugh.md new file mode 100644 index 000000000000..dde4469c6da3 --- /dev/null +++ b/.changeset/shaggy-phones-laugh.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +Fix false negative for a11y_consider_explicit_label with popover elements 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 717ee4bf50d9..301a5b19eb81 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,12 @@ function has_content(element) { } if (node.type === 'RegularElement' || node.type === 'SvelteElement') { + // FIX START: Ignore elements with the popover attribute + if (node.attributes.some((a) => a.type === 'Attribute' && a.name === 'popover')) { + continue; + } + // FIX END + 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 000000000000..98548e737d1b --- /dev/null +++ b/packages/svelte/tests/validator/samples/a11y-popover-label/input.svelte @@ -0,0 +1,17 @@ + + + \ 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 000000000000..b760163647db --- /dev/null +++ b/packages/svelte/tests/validator/samples/a11y-popover-label/warnings.json @@ -0,0 +1,8 @@ +[ + { + "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": 6, "column": 11 } + } +]