Class: ElementComponent::Components::DropdownItem
- Defined in:
- lib/element_component/components/dropdown/item.rb
Constant Summary collapse
- VALID_TYPES =
%i[button link].freeze
Instance Attribute Summary
Attributes inherited from Element
#attributes, #contents, #element, #html
Instance Method Summary collapse
-
#initialize(type: :link, href: "#", active: false, disabled: false, **attributes, &block) ⇒ DropdownItem
constructor
A new instance of DropdownItem.
Methods inherited from Element
#add_attribute, #add_attribute!, #add_content, #add_content!, #new_element, #remove_attribute, #remove_attribute_value, #render, #reset_attributes!, #reset_contents!
Constructor Details
#initialize(type: :link, href: "#", active: false, disabled: false, **attributes, &block) ⇒ DropdownItem
Returns a new instance of DropdownItem.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/element_component/components/dropdown/item.rb', line 8 def initialize(type: :link, href: "#", active: false, disabled: false, **attributes, &block) tag = type == :button ? "button" : "a" super("li", &block) inner = Element.new(tag, class: "dropdown-item", href: (tag == "a" ? href : nil), type: (tag == "button" ? "button" : nil), **attributes) inner.add_attribute(class: "active") if active inner.add_attribute(class: "disabled") if disabled inner.add_attribute(tabindex: "-1") if disabled inner.add_attribute("aria-disabled": "true") if disabled inner.add_content(&block) if block @inner_item = inner end |