From d001536efdfff6a3f9c2a0728a728e2a82f30cd3 Mon Sep 17 00:00:00 2001 From: vibovenkat123 Date: Mon, 20 Feb 2023 19:35:16 -0600 Subject: [PATCH] fix: ignore A11y: element should have child content if the anchor tag has aria-label (#8296) Ignore the error "A11y: element should have child content" if the anchor tag has the aria-label attribute --- src/compiler/compile/nodes/Element.ts | 9 +++++++-- .../a11y-anchor-aria-label-has-no-content/input.svelte | 1 + .../a11y-anchor-aria-label-has-no-content/warnings.json | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 test/validator/samples/a11y-anchor-aria-label-has-no-content/input.svelte create mode 100644 test/validator/samples/a11y-anchor-aria-label-has-no-content/warnings.json diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index cb3d8c718f..3f4d270e6a 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -620,7 +620,7 @@ export default class Element extends Node { const id_attribute = attribute_map.get('id'); const name_attribute = attribute_map.get('name'); const target_attribute = attribute_map.get('target'); - + const aria_label_attribute = attribute_map.get('aria-label'); // links with target="_blank" should have noopener or noreferrer: https://developer.chrome.com/docs/lighthouse/best-practices/external-anchors-use-rel-noopener/ // modern browsers add noopener by default, so we only need to check legacy browsers // legacy browsers don't support noopener so we only check for noreferrer there @@ -641,7 +641,12 @@ export default class Element extends Node { } } } - + if (aria_label_attribute) { + const aria_value = aria_label_attribute.get_static_value(); + if (aria_value != '') { + a11y_required_content.delete('a'); + } + } if (href_attribute) { const href_value = href_attribute.get_static_value(); diff --git a/test/validator/samples/a11y-anchor-aria-label-has-no-content/input.svelte b/test/validator/samples/a11y-anchor-aria-label-has-no-content/input.svelte new file mode 100644 index 0000000000..c13df04b22 --- /dev/null +++ b/test/validator/samples/a11y-anchor-aria-label-has-no-content/input.svelte @@ -0,0 +1 @@ + diff --git a/test/validator/samples/a11y-anchor-aria-label-has-no-content/warnings.json b/test/validator/samples/a11y-anchor-aria-label-has-no-content/warnings.json new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/test/validator/samples/a11y-anchor-aria-label-has-no-content/warnings.json @@ -0,0 +1 @@ +[]