Class: Impulse::Autocomplete::OptionComponent

Inherits:
Impulse::ApplicationComponent show all
Defined in:
app/components/impulse/autocomplete/option_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Impulse::ApplicationComponent

generate_id

Methods included from Helpers::AttributesHelper

#merge_attributes

Constructor Details

#initialize(value:, text:, description: nil, **system_args) ⇒ OptionComponent

Returns a new instance of OptionComponent.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/components/impulse/autocomplete/option_component.rb', line 6

def initialize(value:, text:, description: nil, **system_args)
  @value = value
  @text = text
  @description = description
  @text_id = self.class.generate_id
  @system_args = system_args
  @system_args[:id] = system_args.fetch(:id, self.class.generate_id)
  @system_args[:tag] ||= :div
  @system_args[:role] = :option
  @system_args[:value] = value
  @system_args[:tabindex] = "-1"

  @system_args[:class] = class_names(
    system_args[:class],
    "awc-autocomplete-option dropdown-item",
    disabled: system_args[:disabled]
  )

  @system_args[:"data-text"] = text
  @system_args[:"aria-selected"] = "false"
  @system_args[:"aria-labelledby"] = @text_id
  @system_args[:"aria-disabled"] = (!!system_args[:disabled]).to_s
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



4
5
6
# File 'app/components/impulse/autocomplete/option_component.rb', line 4

def description
  @description
end

#system_argsObject (readonly)

Returns the value of attribute system_args.



4
5
6
# File 'app/components/impulse/autocomplete/option_component.rb', line 4

def system_args
  @system_args
end

#textObject (readonly)

Returns the value of attribute text.



4
5
6
# File 'app/components/impulse/autocomplete/option_component.rb', line 4

def text
  @text
end

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'app/components/impulse/autocomplete/option_component.rb', line 4

def value
  @value
end