Class: Arara::SelectItemComponent

Inherits:
ActionView::Component::Base
  • Object
show all
Includes:
BaseComponent
Defined in:
app/components/arara/select_item_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BaseComponent

#default_data_controller, #default_html_tag, #html_class, #html_content, #html_data, #html_tag, included

Constructor Details

#initialize(value: nil, label: nil, blank: false, selected: false, disabled: false, **kw) ⇒ SelectItemComponent

Returns a new instance of SelectItemComponent.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/components/arara/select_item_component.rb', line 11

def initialize(value: nil, label: nil, blank: false, selected: false, disabled: false, **kw)
  super(tag: "li", **kw)

  @value = value
  @label = label
  @blank = blank
  @disabled = disabled
  @selected = selected
  if blank
    @value = ""
    label = nil
  end
end

Instance Attribute Details

#blankObject (readonly)

Returns the value of attribute blank.



4
5
6
# File 'app/components/arara/select_item_component.rb', line 4

def blank
  @blank
end

#disabledObject (readonly)

Returns the value of attribute disabled.



4
5
6
# File 'app/components/arara/select_item_component.rb', line 4

def disabled
  @disabled
end

#labelObject (readonly)

Returns the value of attribute label.



4
5
6
# File 'app/components/arara/select_item_component.rb', line 4

def label
  @label
end

#selectedObject (readonly)

Returns the value of attribute selected.



4
5
6
# File 'app/components/arara/select_item_component.rb', line 4

def selected
  @selected
end

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'app/components/arara/select_item_component.rb', line 4

def value
  @value
end

Instance Method Details

#default_html_classObject



25
26
27
28
# File 'app/components/arara/select_item_component.rb', line 25

def default_html_class
  return "mdc-list-item mdc-list-item--selected" if selected
  "mdc-list-item"
end

#html_optionsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/components/arara/select_item_component.rb', line 30

def html_options
  opts = super

  opts[:data] ||= {}
  opts[:aria] ||= {}

  opts[:role] = "option"
  opts[:aria][:selected] = selected
  opts[:tabindex] = "-1"
  opts[:data][:value] = value

  opts[:disabled] = "" if disabled
  opts
end