Skip to content

Commit 5c2982d

Browse files
Give inputs unique ids so that SR doesn't skip Label announcement (#3874)
Co-authored-by: primer-css <primer-css@users.noreply.github.com>
1 parent 63b9a74 commit 5c2982d

6 files changed

Lines changed: 23 additions & 7 deletions

File tree

.changeset/hip-flies-pretend.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/view-components": patch
3+
---
4+
5+
Give inputs unique ids so that SR doesn't skip Label announcement

app/lib/primer/forms/dsl/multi_input.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ def decorate_options(name:, **options)
3939
new_options[:data] ||= {}
4040
new_options[:data][:name] = name
4141
new_options[:data][:targets] = "primer-multi-input.fields"
42-
new_options[:id] = nil if options[:hidden]
42+
new_options[:id] = "#{@name}_#{name}"
43+
new_options[:aria] ||= {}
44+
new_options[:aria][:labelledby] = "label-#{base_id}"
4345
new_options[:disabled] = true if options[:hidden] # disable to avoid submitting to server
4446
new_options
4547
end

app/lib/primer/forms/form_control.html.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<% if @input.form_control? %>
22
<%= content_tag(@tag, **@form_group_arguments) do %>
33
<% if @input.label %>
4-
<%= builder.label(@input.name, **@input.label_arguments) do %>
4+
<% label_id = @input.label_arguments[:id] || "label-#{@input.base_id}" %>
5+
<%= builder.label(@input.name, **@input.label_arguments.merge(id: label_id)) do %>
56
<%= @input.label %>
67
<% if @input.required? %>
78
<span aria-hidden="true">*</span>

lib/primer/accessibility.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ module Accessibility
3232
per_component: {
3333
Primer::Alpha::ToggleSwitch => {
3434
all_scenarios: %i[button-name]
35+
},
36+
37+
Primer::Alpha::MultiInput => {
38+
visually_hide_label: %i[label-title-only]
3539
}
3640
}
3741
}
@@ -46,6 +50,8 @@ def ignore_preview?(preview_class)
4650
end
4751

4852
def axe_rules_to_skip(component: nil, scenario_name: nil, flatten: false)
53+
scenario_key = scenario_name.is_a?(String) ? scenario_name.to_sym : scenario_name
54+
4955
to_skip = {
5056
wont_fix: Set.new(AXE_RULES_TO_SKIP.dig(:wont_fix, :global) || []),
5157
will_fix: Set.new(AXE_RULES_TO_SKIP.dig(:will_fix, :global) || [])
@@ -55,9 +61,9 @@ def axe_rules_to_skip(component: nil, scenario_name: nil, flatten: false)
5561
to_skip[:wont_fix].merge(AXE_RULES_TO_SKIP.dig(:wont_fix, :per_component, component, :all_scenarios) || [])
5662
to_skip[:will_fix].merge(AXE_RULES_TO_SKIP.dig(:will_fix, :per_component, component, :all_scenarios) || [])
5763

58-
if scenario_name
59-
to_skip[:wont_fix].merge(AXE_RULES_TO_SKIP.dig(:wont_fix, :per_component, component, scenario_name) || [])
60-
to_skip[:will_fix].merge(AXE_RULES_TO_SKIP.dig(:will_fix, :per_component, component, scenario_name) || [])
64+
if scenario_key
65+
to_skip[:wont_fix].merge(AXE_RULES_TO_SKIP.dig(:wont_fix, :per_component, component, scenario_key) || [])
66+
to_skip[:will_fix].merge(AXE_RULES_TO_SKIP.dig(:will_fix, :per_component, component, scenario_key) || [])
6167
end
6268
end
6369

static/info_arch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5312,7 +5312,8 @@
53125312
"snapshot": "true",
53135313
"skip_rules": {
53145314
"wont_fix": [
5315-
"region"
5315+
"region",
5316+
"label-title-only"
53165317
],
53175318
"will_fix": [
53185319
"color-contrast"

static/previews.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4883,7 +4883,8 @@
48834883
"snapshot": "true",
48844884
"skip_rules": {
48854885
"wont_fix": [
4886-
"region"
4886+
"region",
4887+
"label-title-only"
48874888
],
48884889
"will_fix": [
48894890
"color-contrast"

0 commit comments

Comments
 (0)