Method: Primer::Alpha::Navigation::Tab#initialize

Defined in:
app/components/primer/alpha/navigation/tab.rb

#initialize(list: false, selected: false, with_panel: false, panel_id: "", icon_classes: "", wrapper_arguments: {}, **system_arguments) ⇒ Tab

Returns a new instance of Tab.

Parameters:

  • list (Boolean) (defaults to: false)

    Whether the Tab is an item in a ‘<ul>` list.

  • selected (Boolean) (defaults to: false)

    Whether the Tab is selected or not.

  • with_panel (Boolean) (defaults to: false)

    Whether the Tab has an associated panel.

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

    Only applies if ‘with_panel` is `true`. Unique id of panel.

  • icon_classes (Boolean) (defaults to: "")

    Classes that must always be applied to icons.

  • wrapper_arguments (Hash) (defaults to: {})

    <%= link_to_system_arguments_docs %> to be used in the ‘<li>` wrapper when the tab is an item in a list.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>

[View source]

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/components/primer/alpha/navigation/tab.rb', line 75

def initialize(list: false, selected: false, with_panel: false, panel_id: "", icon_classes: "", wrapper_arguments: {}, **system_arguments)
  @selected = selected
  @icon_classes = icon_classes
  @list = list
  @with_panel = with_panel

  @system_arguments = system_arguments
  @id = @system_arguments[:id]
  @wrapper_arguments = wrapper_arguments

  if with_panel || @system_arguments[:tag] == :button
    @system_arguments[:tag] = :button
    @system_arguments[:type] = :button
    @system_arguments[:role] = :tab
    panel_id(panel_id)
    # https://www.w3.org/TR/wai-aria-practices/#presentation_role
    @wrapper_arguments[:role] = :presentation
  else
    @system_arguments[:tag] = :a
  end

  @wrapper_arguments[:tag] = :li
  @wrapper_arguments[:display] ||= :inline_flex

  return unless @selected

  if @system_arguments[:tag] == :a
    aria_current = aria("current", system_arguments) || DEFAULT_ARIA_CURRENT_FOR_ANCHOR
    @system_arguments[:"aria-current"] = fetch_or_fallback(ARIA_CURRENT_OPTIONS_FOR_ANCHOR, aria_current, DEFAULT_ARIA_CURRENT_FOR_ANCHOR)
  else
    @system_arguments[:"aria-selected"] = true
  end
end