Class: ERBLint::Linters::GitHub::Accessibility::NoVisuallyHiddenInteractiveElements

Inherits:
Linter
  • Object
show all
Includes:
CustomHelpers, LinterRegistry
Defined in:
lib/erblint-github/linters/github/accessibility/no_visually_hidden_interactive_elements.rb

Constant Summary collapse

INTERACTIVE_ELEMENTS =
%w[a button summary select option textarea].freeze
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"

Instance Method Summary collapse

Methods included from CustomHelpers

#basic_conditional_code_check, #counter_correct?, #focusable?, #generate_offense, #generate_offense_from_source_range, #possible_attribute_values, #simple_class_name, #tags

Instance Method Details

#run(processed_source) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/erblint-github/linters/github/accessibility/no_visually_hidden_interactive_elements.rb', line 16

def run(processed_source)
  tags(processed_source).each do |tag|
    next if tag.closing?
    classes = possible_attribute_values(tag, "class")
    if classes.include?("sr-only") && INTERACTIVE_ELEMENTS.include?(tag.name)
      generate_offense(self.class, processed_source, tag)
    end
  end
end