Class: Railsboot::Breadcrumb::ItemComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/railsboot/breadcrumb/item_component.rb

Overview

ViewComponent: renders the item block.

Instance Method Summary collapse

Constructor Details

#initialize(text: "", href: "", active: false, **html_attributes) ⇒ ItemComponent

Returns a new instance of ItemComponent.

Parameters:

  • text (String) (defaults to: "")

    link text for the breadcrumb item

  • href (String) (defaults to: "")

    URL the item links to

  • active (Boolean) (defaults to: false)

    whether the item is the current (active) page

  • html_attributes (Hash)

    additional HTML attributes applied to the rendered element

Options Hash (**html_attributes):

  • :class (String)

    additional CSS classes, merged with the component's own classes



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/components/railsboot/breadcrumb/item_component.rb', line 9

def initialize(text: "", href: "", active: false, **html_attributes)
  @text = text
  @href = href
  @active = active
  @html_attributes = html_attributes

  @html_attributes[:tag] = "li"
  @html_attributes[:class] = class_names(
    "breadcrumb-item",
    { "active" => @active },
    html_attributes.delete(:class)
  )
end

Instance Method Details

#before_rendervoid (protected)

This method returns an undefined value.

Sets the aria-current attribute when the item is active.



27
28
29
# File 'app/components/railsboot/breadcrumb/item_component.rb', line 27

def before_render
  @html_attributes["aria-current"] = "page" if @active
end