class Primer::Alpha::Navigation::Tab
When the selected tab does not correspond to the current page, such as in a nested inner tab, make sure to use aria-current=“true”
‘Tab` renders the selected anchor tab with `aria-current=“page”` by default.
@accessibility
and `Primer::Alpha::UnderlineNav` and should not be used by itself.
This component is part of navigation components such as `Primer::Alpha::TabNav`
def initialize(list: false, selected: false, with_panel: false, panel_id: "", icon_classes: "", wrapper_arguments: {}, **system_arguments)
-
system_arguments
(Hash
) -- <%= link_to_system_arguments_docs %> -
wrapper_arguments
(Hash
) -- <%= link_to_system_arguments_docs %> to be used in the ` - ` wrapper when the tab is an item in a list.
-
icon_classes
(Boolean
) -- Classes that must always be applied to icons. -
panel_id
(String
) -- Only applies if `with_panel` is `true`. Unique id of panel. -
with_panel
(Boolean
) -- Whether the Tab has an associated panel. -
selected
(Boolean
) -- Whether the Tab is selected or not. -
list
(Boolean
) -- Whether the Tab is an item in a `- ` list.
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
def panel_id(panel_id)
def panel_id(panel_id) if panel_id.blank? raise ArgumentError, "`panel_id` is required" unless Rails.env.production? else @panel_id = panel_id @system_arguments[:"aria-controls"] = @panel_id end end
def wrapper
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