x-govuk/govuk-form-builder

Can’t use kwargs on legends

Closed this issue · 1 comments

With the following template

<%= f.govuk_fieldset
  legend: {
    text: 'Question title',
    size: 'xl',
    tag: 'h1',
    a: 'b'
  },
  caption: {
    text: 'Section title',
    a: 'b'
  }
do %><% end %>

the following HTML is output:

<fieldset class="govuk-fieldset">
  <legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
    <h1 class="govuk-fieldset__heading">
      <span class="govuk-caption-m" a="b">Section title</span>
      Question title
    </h1>
  </legend></fieldset>

Note how a=b does not appear on the <legend> element, as suggested in the documentation, and as shown to work as an option for caption.

https://github.com/DFE-Digital/govuk_design_system_formbuilder/blob/d269218348fd976af8f05850664cd38699a22370/lib/govuk_design_system_formbuilder/elements/legend.rb#L7-L28

I’m wondering if @html_attributes = kwargs should appear within the clause when Hash (but that’s just a wild and uninformed stab in the dark).

Yeah, definitely a bug here. You identified the line at fault but the reason is that the custom attributes are in the legend hash and not in kwargs. This class is a bit out of step with its siblings due to the way it used to be structured, I'll bring it inline and add some tests on this behaviour. Thanks for reporting 👍