Skip to content

Commit

Permalink
Fix regression causing check boxes to always render enabled (#1833)
Browse files Browse the repository at this point in the history
  • Loading branch information
camertron authored Feb 17, 2023
1 parent 2a23453 commit a90e155
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/two-clocks-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

Fix regression causing check boxes to always render enabled
4 changes: 2 additions & 2 deletions lib/primer/forms/dsl/check_box_group_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def type
def check_box(**system_arguments, &block)
args = {
name: @name,
**system_arguments,
builder: @builder,
form: @form,
scheme: scheme,
disabled: disabled?
disabled: disabled?,
**system_arguments
}

@check_boxes << CheckBoxInput.new(**args, &block)
Expand Down
36 changes: 36 additions & 0 deletions test/lib/primer/forms/checkbox_group_input_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,40 @@ def test_hidden_checkbox_group
assert_selector "fieldset", visible: :hidden
assert_selector ".FormControl-checkbox-wrap", visible: :hidden
end

class DisabledCheckboxGroupForm < ApplicationForm
form do |check_form|
check_form.check_box_group(label: "Foobar", disabled: true) do |check_group|
check_group.check_box(name: :foo, label: "Foo")
end
end
end

def test_disabled_checkbox_group_disables_constituent_checkboxes
render_in_view_context do
primer_form_with(url: "/foo") do |f|
render(DisabledCheckboxGroupForm.new(f))
end
end

assert_selector ".FormControl-checkbox-wrap input[disabled]"
end

class DisabledCheckboxInGroupForm < ApplicationForm
form do |check_form|
check_form.check_box_group(label: "Foobar") do |check_group|
check_group.check_box(name: :foo, label: "Foo", disabled: true)
end
end
end

def test_checkbox_can_be_individually_disabled_in_group
render_in_view_context do
primer_form_with(url: "/foo") do |f|
render(DisabledCheckboxInGroupForm.new(f))
end
end

assert_selector ".FormControl-checkbox-wrap input[disabled]"
end
end
62 changes: 62 additions & 0 deletions test/lib/primer/forms/radio_button_group_input_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# frozen_string_literal: true

require "lib/test_helper"

class Primer::Forms::RadioButtonGroupInputTest < Minitest::Test
include Primer::ComponentTestHelpers

class HiddenRadioGroupForm < ApplicationForm
form do |radio_form|
radio_form.radio_button_group(name: :foobar, label: "Foobar", hidden: true) do |radio_group|
radio_group.radio_button(name: :foo, value: "Foo", label: "Foo")
end
end
end

def test_hidden_radio_button_group
render_in_view_context do
primer_form_with(url: "/foo") do |f|
render(HiddenRadioGroupForm.new(f))
end
end

assert_selector "fieldset", visible: :hidden
assert_selector ".FormControl-radio-wrap", visible: :hidden
end

class DisabledRadioGroupForm < ApplicationForm
form do |radio_form|
radio_form.radio_button_group(name: :foobar, label: "Foobar", disabled: true) do |radio_group|
radio_group.radio_button(name: :foo, value: "Foo", label: "Foo")
end
end
end

def test_disabled_radio_group_disables_constituent_radios
render_in_view_context do
primer_form_with(url: "/foo") do |f|
render(DisabledRadioGroupForm.new(f))
end
end

assert_selector ".FormControl-radio-wrap input[disabled]"
end

class DisabledRadioInGroupForm < ApplicationForm
form do |radio_form|
radio_form.radio_button_group(name: :foobar, label: "Foobar") do |radio_group|
radio_group.radio_button(name: :foo, value: "Foo", label: "Foo", disabled: true)
end
end
end

def test_radio_can_be_individually_disabled_in_group
render_in_view_context do
primer_form_with(url: "/foo") do |f|
render(DisabledRadioInGroupForm.new(f))
end
end

assert_selector ".FormControl-radio-wrap input[disabled]"
end
end

0 comments on commit a90e155

Please sign in to comment.