-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add config to control boldening of radio labels
The original behaviour of the form builder followed the examples in the Design System documentation at the time and emboldened any radio button labels when hints were present. These examples were dropped in 2020[0] and the guidance changed. In the referenced PR I said I'd look into changing the behaviour in the form builder but never did. As it would be a breaking change we're just adding a new configuration option, `default_collection_radio_buttons_auto_bold_labels`, to allow the behaviour to be modified. [0] alphagov/govuk-design-system#1284
- Loading branch information
1 parent
9575a00
commit 44bd340
Showing
5 changed files
with
87 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
spec/govuk_design_system_formbuilder/builder/configuration/radio_auto_embolden_label_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
describe GOVUKDesignSystemFormBuilder::FormBuilder do | ||
include_context 'setup builder' | ||
include_context 'setup examples' | ||
|
||
describe 'labels auto bolding config' do | ||
specify %(the default should be to bold labels when hints are present) do | ||
expect(GOVUKDesignSystemFormBuilder.config.default_collection_radio_buttons_auto_bold_labels).to be(true) | ||
end | ||
|
||
let(:label_selector) { 'label.govuk-label' } | ||
let(:bold_label_selector) { label_selector + '--s' } | ||
let(:method) { :govuk_collection_radio_buttons } | ||
let(:attribute) { :favourite_shape } | ||
|
||
let(:shapes) do | ||
[ | ||
OpenStruct.new(id: 't', name: 'Triangle', description: 'A three-edged polygon'), | ||
OpenStruct.new(id: 's', name: 'Square', description: 'A regular quadrilateral'), | ||
OpenStruct.new(id: 'p', name: 'Pentagon'), | ||
OpenStruct.new(id: 'h', name: 'Hexagon'), | ||
] | ||
end | ||
|
||
let(:args) { [method, attribute, shapes, :id, :name, :description] } | ||
let(:kwargs) { {} } | ||
|
||
subject { builder.send(*args, **kwargs) } | ||
|
||
context 'when default_collection_radio_buttons_auto_bold_labels is set to true' do | ||
specify 'all of the labels are bold' do | ||
expect(subject).to have_tag(label_selector, count: shapes.size) | ||
expect(subject).to have_tag(bold_label_selector, count: shapes.size) | ||
end | ||
|
||
context %(when the default is overriden with the 'bold_labels' argument) do | ||
let(:kwargs) { { bold_labels: false } } | ||
|
||
specify 'none of the labels are bold' do | ||
expect(subject).to have_tag(label_selector, count: shapes.size) | ||
expect(subject).not_to have_tag(bold_label_selector) | ||
end | ||
end | ||
end | ||
|
||
context 'when default_collection_radio_buttons_auto_bold_labels is set to false' do | ||
before do | ||
GOVUKDesignSystemFormBuilder.configure do |conf| | ||
conf.default_collection_radio_buttons_auto_bold_labels = false | ||
end | ||
end | ||
|
||
after { GOVUKDesignSystemFormBuilder.reset! } | ||
|
||
specify 'none of the labels are bold' do | ||
expect(subject).to have_tag(label_selector, count: shapes.size) | ||
expect(subject).not_to have_tag(bold_label_selector) | ||
end | ||
|
||
context %(when the default is overriden with the 'bold_labels' argument) do | ||
let(:kwargs) { { bold_labels: true } } | ||
|
||
specify 'all of the labels are bold' do | ||
expect(subject).to have_tag(label_selector, count: shapes.size) | ||
expect(subject).to have_tag(bold_label_selector, count: shapes.size) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters