fix: silence no content a11y warning if the tag has an aria-label (#8299)

fixes #8296

---------

Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
pull/8311/head
Vaibhav 2 years ago committed by GitHub
parent 3559997223
commit c9a269c149
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -225,6 +225,7 @@ export default class Element extends Node {
namespace: string; namespace: string;
needs_manual_style_scoping: boolean; needs_manual_style_scoping: boolean;
tag_expr: Expression; tag_expr: Expression;
contains_a11y_label: boolean;
get is_dynamic_element() { get is_dynamic_element() {
return this.name === 'svelte:element'; return this.name === 'svelte:element';
@ -625,6 +626,7 @@ export default class Element extends Node {
const id_attribute = attribute_map.get('id'); const id_attribute = attribute_map.get('id');
const name_attribute = attribute_map.get('name'); const name_attribute = attribute_map.get('name');
const target_attribute = attribute_map.get('target'); 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/ // 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 // modern browsers add noopener by default, so we only need to check legacy browsers
@ -647,6 +649,13 @@ export default class Element extends Node {
} }
} }
if (aria_label_attribute) {
const aria_value = aria_label_attribute.get_static_value();
if (aria_value != '') {
this.contains_a11y_label = true;
}
}
if (href_attribute) { if (href_attribute) {
const href_value = href_attribute.get_static_value(); const href_value = href_attribute.get_static_value();
@ -930,6 +939,7 @@ export default class Element extends Node {
validate_content() { validate_content() {
if (!a11y_required_content.has(this.name)) return; if (!a11y_required_content.has(this.name)) return;
if (this.contains_a11y_label) return;
if ( if (
this.bindings this.bindings
.some((binding) => ['textContent', 'innerHTML'].includes(binding.name)) .some((binding) => ['textContent', 'innerHTML'].includes(binding.name))

Loading…
Cancel
Save