Sha256: dbed841e3cc3e94a4599a96f66f1c3eae8579d598c44bd2ed46a7493764a61d2

Contents?: true

Size: 1 KB

Versions: 2

Compression:

Stored size: 1 KB

Contents

module GOVUKDesignSystemFormBuilder
  module Containers
    class Fieldset < Base
      def initialize(builder, object_name = nil, attribute_name = nil, legend: {}, caption: {}, described_by: nil, &block)
        super(builder, object_name, attribute_name, &block)

        @legend         = legend
        @caption        = caption
        @described_by   = described_by(described_by)
        @attribute_name = attribute_name
      end

      def html
        content_tag('fieldset', **options) do
          safe_join([legend_element, (@block_content || yield)])
        end
      end

    private

      def options
        {
          class: classes,
          aria: { describedby: @described_by }
        }
      end

      def classes
        %(#{brand}-fieldset)
      end

      def legend_element
        @legend_element ||= Elements::Legend.new(@builder, @object_name, @attribute_name, **legend_options)
      end

      def legend_options
        { legend: @legend, caption: @caption }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
govuk_design_system_formbuilder-1.2.6 lib/govuk_design_system_formbuilder/containers/fieldset.rb
govuk_design_system_formbuilder-1.2.5 lib/govuk_design_system_formbuilder/containers/fieldset.rb