Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chatty-pants-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

Fix incorrect label `for` attribute value when `scope_id_false: false`
3 changes: 2 additions & 1 deletion app/lib/primer/forms/dsl/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def initialize(builder:, form:, **system_arguments)
@input_arguments = system_arguments
@input_arguments.delete(:id) unless @input_arguments[:id].present?
@label_arguments = @input_arguments.delete(:label_arguments) || {}
@label_arguments[:for] = id if id.present?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was calling def id below which is the same as @input_arguments[:id] curious how this is different than what was already in place


@label_arguments[:class] = class_names(
@label_arguments[:class],
Expand Down Expand Up @@ -102,6 +101,8 @@ def initialize(builder:, form:, **system_arguments)
end
# rubocop:enable Style/IfUnlessModifier

@label_arguments[:for] = @input_arguments[:id]

# Whether or not to wrap the component in a FormControl, which renders a
# label above and validation message beneath the input.
@form_control = @input_arguments.delete(:form_control) { true }
Expand Down
2 changes: 2 additions & 0 deletions test/lib/primer/forms/input_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def test_removes_model_scope_from_name_and_id
end

assert_selector "input#ultimate_answer[name=ultimate_answer]"
assert_selector "label[for=ultimate_answer]"
end

def test_uses_given_id
Expand All @@ -116,5 +117,6 @@ def test_uses_given_id
end

assert_selector "input#foobar[name=ultimate_answer]"
assert_selector "label[for=foobar]"
end
end