Skip to content

Commit

Permalink
Merge pull request #511 from thomasleese/legend-size-nil
Browse files Browse the repository at this point in the history
Allow legend size to be nil
  • Loading branch information
peteryates authored Jul 17, 2024
2 parents 8c0fb5d + 6d4f042 commit 0dbc552
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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

0 comments on commit 0dbc552

Please sign in to comment.