Class: Primer::Forms::FieldsetGroup

Inherits:
BaseComponent show all
Defined in:
app/lib/primer/forms/fieldset_group.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from BaseComponent

#content, inherited, #input?, #perform_render, #render?, #to_component, #type

Methods included from ActsAsComponent

#base_template_path, #compile!, extended, #renders_templates, #template_root_path

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(title:, inputs:, builder:, form:, layout: Primer::Forms::Group::DEFAULT_LAYOUT, heading_arguments: {}, group_arguments: {}, **system_arguments) ⇒ FieldsetGroup

Returns a new instance of FieldsetGroup.

Parameters:

  • title (String)

    The title displayed as the heading for the fieldset

  • inputs (Array<Primer::Forms::Dsl::Input>)

    Array of form inputs to be grouped

  • builder (ActionView::Helpers::FormBuilder)

    The form builder instance

  • form (Primer::Forms::BaseForm)

    The form object

  • layout (Symbol) (defaults to: Primer::Forms::Group::DEFAULT_LAYOUT)

    Layout style for the input group (default: :default_layout)

  • heading_arguments (Hash) (defaults to: {})

    Arguments passed to the heading component

  • group_arguments (Hash) (defaults to: {})

    Arguments passed to the input group component

  • system_arguments (Hash)

    Additional system arguments passed to the section wrapper

Options Hash (heading_arguments:):

  • :id (String)

    The ID for the heading element

  • :tag (Symbol)

    The HTML tag for the heading (default: :h3)

  • :size (Symbol)

    The size of the heading (default: :medium)



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/lib/primer/forms/fieldset_group.rb', line 19

def initialize( # rubocop:disable Metrics/AbcSize
  title:,
  inputs:,
  builder:,
  form:,
  layout: Primer::Forms::Group::DEFAULT_LAYOUT,
  heading_arguments: {},
  group_arguments: {},
  **system_arguments
)
  super()

  @title = title

  @heading_arguments = heading_arguments
  @heading_arguments[:id] ||= "subhead-#{SecureRandom.uuid}"
  @heading_arguments[:tag] ||= :h3
  @heading_arguments[:size] ||= :medium

  @fieldset_arguments = {
    legend_text: @title,
    visually_hide_legend: true,
    aria: { labelledby: @heading_arguments[:id] }
  }
  @group_arguments = group_arguments.merge(inputs:, builder:, form:, layout:)

  @system_arguments = system_arguments
  @system_arguments[:tag] = :section
  @system_arguments[:mb] ||= 4
  @system_arguments[:aria] ||= {}
  @system_arguments[:aria][:labelledby] = @heading_arguments[:id]
  @system_arguments[:hidden] = :none if inputs.all?(&:hidden?)
end