Commit 6f8ad5c5 authored by Pavel Shutsin's avatar Pavel Shutsin

Merge branch 'fix-gitlab-ui-checkbox-component' into 'master'

Fix gitlab_ui_checkbox_component when { multiple: true }

See merge request gitlab-org/gitlab!80155
parents 7192b924 927afbeb
......@@ -16,13 +16,15 @@ module Gitlab
:div,
class: 'gl-form-checkbox custom-control custom-checkbox'
) do
value = checkbox_options[:multiple] ? checked_value : nil
@template.check_box(
@object_name,
method,
format_options(checkbox_options, ['custom-control-input']),
checked_value,
unchecked_value
) + generic_label(method, label, label_options, help_text: help_text)
) + generic_label(method, label, label_options, help_text: help_text, value: value)
end
end
......
......@@ -78,6 +78,29 @@ RSpec.describe Gitlab::FormBuilders::GitlabUiFormBuilder do
expect(fake_template).to have_received(:label).with(:user, :view_diffs_file_by_file, { class: %w(custom-control-label label-foo-bar), object: user, value: nil })
end
end
context 'with checkbox_options: { multiple: true }' do
let(:optional_args) do
{
checkbox_options: { multiple: true },
checked_value: 'one',
unchecked_value: false
}
end
it 'renders labels with correct for attributes' do
expected_html = <<~EOS
<div class="gl-form-checkbox custom-control custom-checkbox">
<input class="custom-control-input" type="checkbox" value="one" name="user[view_diffs_file_by_file][]" id="user_view_diffs_file_by_file_one" />
<label class="custom-control-label" for="user_view_diffs_file_by_file_one">
Show one file at a time on merge request&#39;s Changes tab
</label>
</div>
EOS
expect(checkbox_html).to eq(html_strip_whitespace(expected_html))
end
end
end
describe '#gitlab_ui_radio_component' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment