Class: SdrViewComponents::TabForm::TabListComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/sdr_view_components/tab_form/tab_list_component.rb

Overview

Component for rendering tabbed navigation for a form.

TabListComponent doesn't render a

tag itself -- the real is rendered separately (see HiddenFieldsFormComponent), and the panes' fields are associated with it via the HTML form attribute (see TabbedFormBuilder) rather than DOM nesting, since panes aren't necessarily inside the .

Panes can be any renderable object; if it responds to active_tab_name=, that's set for you before rendering, so panes don't have to be passed active_tab_name at construction.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseComponent

#args_for, #mark_label_required, #merge_actions, #merge_classes

Constructor Details

#initialize(id:, active_tab_name:, classes: [], data: {}) ⇒ TabListComponent

Returns a new instance of TabListComponent.



18
19
20
21
22
23
24
# File 'app/components/sdr_view_components/tab_form/tab_list_component.rb', line 18

def initialize(id:, active_tab_name:, classes: [], data: {})
  @id = id
  @active_tab_name = active_tab_name
  @classes = classes
  @data = data
  super()
end

Instance Attribute Details

#active_tab_nameObject (readonly)

Returns the value of attribute active_tab_name.



26
27
28
# File 'app/components/sdr_view_components/tab_form/tab_list_component.rb', line 26

def active_tab_name
  @active_tab_name
end

#idObject (readonly)

Returns the value of attribute id.



26
27
28
# File 'app/components/sdr_view_components/tab_form/tab_list_component.rb', line 26

def id
  @id
end

Instance Method Details

#classesObject



28
29
30
31
32
# File 'app/components/sdr_view_components/tab_form/tab_list_component.rb', line 28

def classes
  # Provides tab-error, tab-form as the static default classes
  # merged with any additional classes passed in.
  merge_classes(%w[tab-error row tab-form gx-4 gy-4 mb-5], @classes)
end

#dataObject

change events fired by fields anywhere in the panes bubble up to this component's root element (fields are associated with the real form via the form attribute, not DOM nesting, so actions can't live on the <form> tag itself).



37
38
39
# File 'app/components/sdr_view_components/tab_form/tab_list_component.rb', line 37

def data
  @data.merge(controller: 'sdr-tab-error')
end

#invalid_description_idObject



41
42
43
# File 'app/components/sdr_view_components/tab_form/tab_list_component.rb', line 41

def invalid_description_id
  "#{id}-invalid-description"
end