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

Allow legend size to be nil #511

Merged
merged 1 commit into from
Jul 17, 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
2 changes: 2 additions & 0 deletions lib/govuk_design_system_formbuilder/elements/legend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def retrieve_text(supplied_text)
end

def size_class(size)
return nil if size.nil?

fail "invalid size '#{size}', must be xl, l, m or s" unless size.in?(%w(xl l m s))

%(fieldset__legend--#{size})
Expand Down
12 changes: 12 additions & 0 deletions spec/support/shared/shared_legend_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
context 'valid sizes' do
%w(s m l xl).each do |size|
let(:size) { size }

context %(when the legend size is #{size}) do
subject { builder.send(*args, legend: { text: legend_text, size: }) }

Expand All @@ -53,6 +54,17 @@
end
end
end

context 'when the legend size is nil' do
subject { builder.send(*args, legend: { text: legend_text, size: nil }) }

specify 'the size class should be absent' do
expect(subject).to_not have_tag('legend', with: { class: 'govuk-fieldset__legend--s' })
expect(subject).to_not have_tag('legend', with: { class: 'govuk-fieldset__legend--m' })
expect(subject).to_not have_tag('legend', with: { class: 'govuk-fieldset__legend--l' })
expect(subject).to_not have_tag('legend', with: { class: 'govuk-fieldset__legend--xl' })
end
end
end

context 'with an invalid size' do
Expand Down
Loading