Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Forms] Fix position of caption for checkbox and radio groups #3072

Merged
merged 6 commits into from
Sep 12, 2024
Merged
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/curvy-apes-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': minor
---

[Forms] Fix position of caption for checkbox and radio groups
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/forms/check_box_group_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# :nodoc:
class CheckBoxGroupForm < ApplicationForm
form do |check_form|
check_form.check_box_group(label: "I like to eat, eat, eat:") do |check_group|
check_form.check_box_group(label: "I like to eat, eat, eat:", caption: "Nom nom nom") do |check_group|
check_group.check_box(
name: "long_a",
label: "Ey-ples and ba-naynays",
Expand Down
6 changes: 5 additions & 1 deletion app/forms/radio_button_group_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
# :nodoc:
class RadioButtonGroupForm < ApplicationForm
form do |radio_form|
radio_form.radio_button_group(name: "channel", label: "How did you hear about us?") do |radio_group|
radio_form.radio_button_group(
name: "channel",
label: "How did you hear about us?",
caption: "We love our listeners"
) do |radio_group|
radio_group.radio_button(value: "online", label: "Online advertisement", caption: "Facebook maybe?")
radio_group.radio_button(value: "radio", label: "Radio advertisement", caption: "We love us some NPR")
radio_group.radio_button(value: "friend", label: "From a friend", caption: "Wow, what a good person")
Expand Down
6 changes: 3 additions & 3 deletions lib/primer/forms/check_box_group.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<%= @input.label %>
<% end %>
<% end %>
<div class="mb-2">
<%= render(Caption.new(input: @input)) %>
</div>
<%= render(SpacingWrapper.new) do %>
<% @input.check_boxes.each do |check_box| %>
<%= render(check_box.to_component) %>
Expand All @@ -14,7 +17,4 @@
<div class="mt-2">
<%= render(ValidationMessage.new(input: @input)) %>
</div>
<div class="mt-2">
<%= render(Caption.new(input: @input)) %>
</div>
</div>
2 changes: 1 addition & 1 deletion lib/primer/forms/check_box_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CheckBoxGroup < BaseComponent

def initialize(input:)
@input = input
@input.add_label_classes("FormControl-label", "mb-2")
@input.add_label_classes("FormControl-label")
Primer::Forms::Utils.classify(@input.input_arguments)
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/primer/forms/radio_button_group.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<%= @input.label %>
<% end %>
<% end %>
<div class="mb-2">
<%= render(Caption.new(input: @input)) %>
</div>
<%= render(SpacingWrapper.new) do %>
<% @input.radio_buttons.each do |radio_button| %>
<%= render(radio_button.to_component) %>
Expand All @@ -14,7 +17,4 @@
<div class="mt-2">
<%= render(ValidationMessage.new(input: @input)) %>
</div>
<div class="mt-2">
<%= render(Caption.new(input: @input)) %>
</div>
</div>
2 changes: 1 addition & 1 deletion lib/primer/forms/radio_button_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class RadioButtonGroup < BaseComponent

def initialize(input:)
@input = input
@input.add_label_classes("FormControl-label", "mb-2")
@input.add_label_classes("FormControl-label")
Primer::Forms::Utils.classify(@input.input_arguments)
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/lib/primer/forms/radio_button_group_input_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_validations
refute_selector "input[type=radio][invalid]"

# should have a validation message
validation_id = page.find("fieldset")["aria-describedby"]
validation_id = page.find("fieldset")["aria-describedby"].split(" ").find { |id| id.start_with?("validation-") }
assert_selector ".FormControl-inlineValidation[id='#{validation_id}']", text: /Channel can['’]t be blank/

# first radio button should have focus
Expand Down
Loading