Module: Primer::Accessibility

Defined in:
lib/primer/accessibility.rb

Overview

:nodoc:

Constant Summary collapse

IGNORED_PREVIEWS =

Skip axe checks for components that should be tested as part of a larger component. Do not add to this list for any other reason!

[
  Primer::Beta::MarkdownPreview,
  Primer::Beta::AutoCompleteItemPreview
].freeze
AXE_RULES_TO_SKIP =

Skip :region which relates to preview page structure rather than individual component. Skip :color-contrast which requires primer design-level change.

{
  # these will be skipped in CI but will still be tracked in Datadog
  will_fix: {
    global: %i[
      color-contrast
    ],

    per_component: {}
  },

  # these will always be skipped
  wont_fix: {
    global: %i[
      region
    ],

    per_component: {
      Primer::Alpha::ToggleSwitch => {
        all_scenarios: %i[button-name]
      },

      Primer::Alpha::MultiInput => {
        visually_hide_label: %i[label-title-only]
      }
    }
  }
}.freeze

Class Method Summary collapse

Class Method Details

.axe_rules_to_skip(component: nil, scenario_name: nil, flatten: false) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/primer/accessibility.rb', line 52

def axe_rules_to_skip(component: nil, scenario_name: nil, flatten: false)
  scenario_key = scenario_name.is_a?(String) ? scenario_name.to_sym : scenario_name

  to_skip = {
    wont_fix: Set.new(AXE_RULES_TO_SKIP.dig(:wont_fix, :global) || []),
    will_fix: Set.new(AXE_RULES_TO_SKIP.dig(:will_fix, :global) || [])
  }

  if component
    to_skip[:wont_fix].merge(AXE_RULES_TO_SKIP.dig(:wont_fix, :per_component, component, :all_scenarios) || [])
    to_skip[:will_fix].merge(AXE_RULES_TO_SKIP.dig(:will_fix, :per_component, component, :all_scenarios) || [])

    if scenario_key
      to_skip[:wont_fix].merge(AXE_RULES_TO_SKIP.dig(:wont_fix, :per_component, component, scenario_key) || [])
      to_skip[:will_fix].merge(AXE_RULES_TO_SKIP.dig(:will_fix, :per_component, component, scenario_key) || [])
    end
  end

  if flatten
    flattened = to_skip.each_with_object(Set.new) do |(_, rule_set), memo|
      memo.merge(rule_set)
    end

    return flattened.to_a
  end

  to_skip.transform_values(&:to_a)
end

.ignore_preview?(preview_class) ⇒ Boolean

rubocop:enable Style/ClassMethodsDefinitions

Returns:

  • (Boolean)


48
49
50
# File 'lib/primer/accessibility.rb', line 48

def ignore_preview?(preview_class)
  IGNORED_PREVIEWS.include?(preview_class)
end