Class: Primer::Alpha::Navigation::Tab

Inherits:
Component
  • Object
show all
Defined in:
app/components/primer/alpha/navigation/tab.rb

Overview

This component is part of navigation components such as ‘Primer::Alpha::TabNav` and `Primer::Alpha::UnderlineNav` and should not be used by itself.

Direct Known Subclasses

Navigation::TabComponent

Constant Summary collapse

DEFAULT_ARIA_CURRENT_FOR_ANCHOR =
:page
ARIA_CURRENT_OPTIONS_FOR_ANCHOR =
[true, DEFAULT_ARIA_CURRENT_FOR_ANCHOR].freeze

Constants inherited from Component

Component::INVALID_ARIA_LABEL_TAGS

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from TestSelectorHelper

TestSelectorHelper::TEST_SELECTOR_TAG

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Constants included from Primer::AttributesHelper

Primer::AttributesHelper::PLURAL_ARIA_ATTRIBUTES, Primer::AttributesHelper::PLURAL_DATA_ATTRIBUTES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Component

deprecated?, generate_id

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from TestSelectorHelper

#add_test_selector

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?

Methods included from ClassNameHelper

#class_names

Methods included from Primer::AttributesHelper

#aria, #data, #extract_data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes

Methods included from ExperimentalSlotHelpers

included

Methods included from ExperimentalRenderHelpers

included

Constructor Details

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



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

Instance Attribute Details

#selectedObject (readonly)

Returns the value of attribute selected.



66
67
68
# File 'app/components/primer/alpha/navigation/tab.rb', line 66

def selected
  @selected
end

Instance Method Details

#wrapperObject



109
110
111
112
113
114
115
116
117
118
# File 'app/components/primer/alpha/navigation/tab.rb', line 109

def wrapper
  unless @list
    yield
    return # returning `yield` caused a double render
  end

  render(Primer::BaseComponent.new(**@wrapper_arguments)) do
    yield if block_given?
  end
end