diff --git a/.changeset/tall-avocados-repair.md b/.changeset/tall-avocados-repair.md new file mode 100644 index 000000000000..cf11fc961000 --- /dev/null +++ b/.changeset/tall-avocados-repair.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: silence a11y warning for inert 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 5db31314d466..f45a6c9a80d6 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 @@ -387,7 +387,10 @@ export function check_element(node, context) { switch (node.name) { case 'a': case 'button': { - const is_hidden = get_static_value(attribute_map.get('aria-hidden')) === 'true'; + const is_hidden = + get_static_value(attribute_map.get('aria-hidden')) === 'true' || + get_static_value(attribute_map.get('inert')) !== null; + if (!has_spread && !is_hidden && !is_labelled && !has_content(node)) { w.a11y_consider_explicit_label(node); } 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 11dc007352fa..e97951065da2 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 @@ -5,6 +5,7 @@ +