diff --git a/README.md b/README.md index eb4b51d..785d11e 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ inherit_gem: - [GitHub::Accessibility::NoAriaLabelMisuse](./docs/rules/accessibility/no-aria-label-misuse.md) - [GitHub::Accessibility::NoPositiveTabIndex](./docs/rules/accessibility/no-positive-tab-index.md) - [GitHub::Accessibility::NoRedundantImageAlt](./docs/rules/accessibility/no-redundant-image-alt.md) +- [GitHub::Accessibility::NoVisuallyHiddenInteractiveElements](./docs/rules/accessibility/no-visually-hidden-interactive-elements.md) - [GitHub::Accessibility::NoTitleAttribute](./docs/rules/accessibility/no-title-attribute.md) - [GitHub::Accessibility::SvgHasAccessibleText](./docs/rules/accessibility/svg-has-accessible-text.md) diff --git a/lib/erblint-github/linters/github/accessibility/no_visually_hidden_interactive_elements.rb b/lib/erblint-github/linters/github/accessibility/no_visually_hidden_interactive_elements.rb index d431763..3890c7d 100644 --- a/lib/erblint-github/linters/github/accessibility/no_visually_hidden_interactive_elements.rb +++ b/lib/erblint-github/linters/github/accessibility/no_visually_hidden_interactive_elements.rb @@ -14,14 +14,10 @@ class NoVisuallyHiddenInteractiveElements < Linter MESSAGE = "Avoid visually hidding interactive elements. Visually hiding interactive elements can be confusing to sighted keyboard users as it appears their focus has been lost when they navigate to the hidden element" def run(processed_source) - visually_hidden = false - tags(processed_source).each do |tag| next if tag.closing? classes = possible_attribute_values(tag, "class") - visually_hidden = true if classes.include?("sr-only") - next unless classes.include?("sr-only") || visually_hidden - if INTERACTIVE_ELEMENTS.include?(tag.name) + if classes.include?("sr-only") && INTERACTIVE_ELEMENTS.include?(tag.name) generate_offense(self.class, processed_source, tag) end end diff --git a/test/linters/accessibility/no_visually_hidden_interactive_elements_test.rb b/test/linters/accessibility/no_visually_hidden_interactive_elements_test.rb index 0a5e7e0..5088e9d 100644 --- a/test/linters/accessibility/no_visually_hidden_interactive_elements_test.rb +++ b/test/linters/accessibility/no_visually_hidden_interactive_elements_test.rb @@ -38,12 +38,13 @@ def test_does_not_warn_if_element_is_interactive_and_shown_on_focus assert_empty @linter.offenses end - def test_warn_if_element_is_interactive_in_a_visually_hidden_parent - @file = "
" + def test_does_not_warn_on_unexpected_elements + @file = <<~ERB + + + ERB @linter.run(processed_source) - assert_equal(1, @linter.offenses.count) - error_messages = @linter.offenses.map(&:message).sort - assert_match(/Avoid visually hidding interactive elements. Visually hiding interactive elements can be confusing to sighted keyboard users as it appears their focus has been lost when they navigate to the hidden element/, error_messages.last) + assert_empty @linter.offenses end end