Skip to content

Commit

Permalink
fix(lint/noSvgWithoutTitle): skip on aria-hidden (#928)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasucp1207 authored Nov 28, 2023
1 parent 514a688 commit 01309e8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ impl Rule for NoSvgWithoutTitle {
return None;
}

if let Some(aria_hidden_attr) = node.find_attribute_by_name("aria-hidden") {
if let Some(attr_static_val) = aria_hidden_attr.as_static_value() {
let attr_text = attr_static_val.text();
if attr_text == "true" {
return None;
}
}
}

// Checks if a `svg` element has a valid `title` element is in a childlist
let jsx_element = node.parent::<JsxElement>()?;
if let AnyJsxElement::JsxOpeningElement(_) = node {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@
<title>implicit role</title>
<span>Pass</span>
</svg>

<svg aria-hidden="true">
<defs>
<pattern>
<path d="M.5 200V.5H200" fill="none" />
</pattern>
</defs>
</svg>
</>;
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ expression: valid.jsx
<title>implicit role</title>
<span>Pass</span>
</svg>

<svg aria-hidden="true">
<defs>
<pattern>
<path d="M.5 200V.5H200" fill="none" />
</pattern>
</defs>
</svg>
</>;

```
Expand Down

0 comments on commit 01309e8

Please sign in to comment.