Method: Primer::Beta::NavList::Item#initialize

Defined in:
app/components/primer/beta/nav_list/item.rb

#initialize(selected_item_id: nil, selected_by_ids: [], sub_item: false, expanded: false, **system_arguments) ⇒ Item

Returns a new instance of Item.

Parameters:

  • selected_item_id (Symbol) (defaults to: nil)

    The ID of the currently selected list item. Used internally.

  • selected_by_ids (Array<Symbol>) (defaults to: [])

    The list of IDs that select this item. In other words, if the selected_item_id attribute on the parent NavList is set to one of these IDs, the item will appear selected.

  • expanded (Boolean) (defaults to: false)

    Whether this item shows (expands) or hides (collapses) its list of sub items.

  • sub_item (Boolean) (defaults to: false)

    Whether or not this item is nested under a parent item. Used internally.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/components/primer/beta/nav_list/item.rb', line 32

def initialize(selected_item_id: nil, selected_by_ids: [], sub_item: false, expanded: false, **system_arguments)
  @selected_item_id = selected_item_id
  @selected_by_ids = Array(selected_by_ids)
  @expanded = expanded
  @sub_item = sub_item

  system_arguments[:classes] = class_names(
    system_arguments[:classes],
    "ActionListItem--subItem" => @sub_item
  )

  @sub_list_arguments = {
    classes: class_names(
      "ActionList",
      "ActionList--subGroup"
    )
  }

  @list = system_arguments[:list]

  @sub_list_arguments["data-action"] = "keydown:#{@list.custom_element_name}#handleItemWithSubItemKeydown" if @list

  overrides = { "data-item-id": @selected_by_ids.join(" ") }

  super(**system_arguments, **overrides)
end