|
1 |
| -use crate::services::aria::Aria; |
| 1 | +use crate::{ |
| 2 | + a11y::{is_content_editable, is_hidden_from_screen_reader}, |
| 3 | + services::aria::Aria, |
| 4 | +}; |
2 | 5 | use biome_analyze::{Rule, RuleDiagnostic, RuleSource, context::RuleContext, declare_lint_rule};
|
3 | 6 | use biome_console::markup;
|
4 | 7 | use biome_js_syntax::jsx_ext::AnyJsxElement;
|
@@ -96,8 +99,8 @@ impl Rule for NoNoninteractiveElementInteractions {
|
96 | 99 |
|
97 | 100 | if !has_handler_props(element)
|
98 | 101 | || is_content_editable(element)
|
99 |
| - || has_presentation_role(element) |
100 |
| - || is_hidden_from_screen_reader(element)? |
| 102 | + || aria_roles.is_presentation_role(element) |
| 103 | + || is_hidden_from_screen_reader(element) |
101 | 104 | || has_interactive_role
|
102 | 105 | {
|
103 | 106 | return None;
|
@@ -163,53 +166,3 @@ fn has_handler_props(element: &AnyJsxElement) -> bool {
|
163 | 166 | .iter()
|
164 | 167 | .any(|handler| element.find_attribute_by_name(handler).is_some())
|
165 | 168 | }
|
166 |
| - |
167 |
| -/// Check if the element's implicit ARIA semantics have been removed. |
168 |
| -/// See https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/presentation_role |
169 |
| -/// |
170 |
| -/// Ref: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/v6.10.0/src/util/isPresentationRole.js |
171 |
| -fn has_presentation_role(element: &AnyJsxElement) -> bool { |
172 |
| - if let Some(attribute) = element.find_attribute_by_name("role") { |
173 |
| - let value = attribute.as_static_value(); |
174 |
| - if let Some(value) = value { |
175 |
| - return matches!(value.as_string_constant(), Some("presentation" | "none")); |
176 |
| - } |
177 |
| - } |
178 |
| - false |
179 |
| -} |
180 |
| - |
181 |
| -/// Check the element is hidden from screen reader. |
182 |
| -/// See |
183 |
| -/// - https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-hidden |
184 |
| -/// - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/hidden |
185 |
| -/// |
186 |
| -/// Ref: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/v6.10.0/src/util/isHiddenFromScreenReader.js |
187 |
| -fn is_hidden_from_screen_reader(element_name: &AnyJsxElement) -> Option<bool> { |
188 |
| - let is_aria_hidden = element_name.has_truthy_attribute("aria-hidden"); |
189 |
| - |
190 |
| - let name = element_name.name_value_token().ok()?; |
191 |
| - |
192 |
| - let is_input_hidden = if name.text_trimmed() == "input" { |
193 |
| - element_name |
194 |
| - .find_attribute_by_name("type") |
195 |
| - .and_then(|attribute| attribute.as_static_value()) |
196 |
| - .and_then(|value| value.as_string_constant().map(|value| value == "hidden")) |
197 |
| - .unwrap_or_default() |
198 |
| - } else { |
199 |
| - false |
200 |
| - }; |
201 |
| - |
202 |
| - Some(is_aria_hidden || is_input_hidden) |
203 |
| -} |
204 |
| - |
205 |
| -/// Check if the element is `contentEditable` |
206 |
| -/// See https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/contenteditable |
207 |
| -/// |
208 |
| -/// Ref: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/v6.10.0/src/util/isContentEditable.js |
209 |
| -fn is_content_editable(element: &AnyJsxElement) -> bool { |
210 |
| - element |
211 |
| - .find_attribute_by_name("contentEditable") |
212 |
| - .and_then(|attribute| attribute.as_static_value()) |
213 |
| - .and_then(|value| value.as_string_constant().map(|value| value == "true")) |
214 |
| - .unwrap_or_default() |
215 |
| -} |
0 commit comments