class Primer::Beta::IconButton
[Learn more about best functional image practices (WAI Images)](www.w3.org/WAI/tutorials/images/functional)
Either ‘aria-label` or `aria-description` will be used for the `Tooltip` text, depending on which one is present.
Either `aria-label` or `aria-description` will be used for the `Tooltip` text, depending on which one is present.
`“Search”` instead of `“Magnifying glass”`.
if your `IconButton` renders a magnifying glass icon and invokes a search action, the `aria-label` should be
The `aria-label` should describe the action to be invoked rather than the icon itself. For instance,
`IconButton` requires an `aria-label`, which will provide assistive technologies with an accessible label.
@accessibility
`IconButton` will always render with a tooltip unless the tag is `:summary`.
Use `IconButton` to render Icon-only buttons without the default button styles.
def initialize(icon:, scheme: DEFAULT_SCHEME, show_tooltip: true, tooltip_direction: Primer::Alpha::Tooltip::DIRECTION_DEFAULT, size: Primer::Beta::Button::DEFAULT_SIZE, disabled: false, **system_arguments)
-
system_arguments
(Hash
) -- <%= link_to_system_arguments_docs %> -
tooltip_direction
(Symbol
) -- (Primer::Alpha::Tooltip::DIRECTION_DEFAULT) <%= one_of(Primer::Alpha::Tooltip::DIRECTION_OPTIONS) %> -
show_tooltip
(Boolean
) -- Whether or not to show a tooltip when this button is hovered. Tooltips should only be hidden if the aria label is redundant, i.e. if the icon has a widely understood definition. -
aria-description
(String
) -- String that can be read by assistive technology. A description can be longer as it is intended to provide more context and information. See the accessibility section for more information. -
aria-label
(String
) -- String that can be read by assistive technology. A label should be short and concise. See the accessibility section for more information. -
type
(Symbol
) -- <%= one_of(Primer::Beta::BaseButton::TYPE_OPTIONS) %> -
disabled
(Boolean
) -- Whether or not the button is disabled. If true, this option forces `tag:` to `:button`. -
size
(Symbol
) -- <%= one_of(Primer::Beta::Button::SIZE_OPTIONS) %> -
scheme
(Symbol
) -- <%= one_of(Primer::Beta::IconButton::SCHEME_OPTIONS) %> -
tag
(Symbol
) -- <%= one_of(Primer::Beta::BaseButton::TAG_OPTIONS) %> -
icon
(String
) -- Name of <%= link_to_octicons %> to use.
def initialize(icon:, scheme: DEFAULT_SCHEME, show_tooltip: true, tooltip_direction: Primer::Alpha::Tooltip::DIRECTION_DEFAULT, size: Primer::Beta::Button::DEFAULT_SIZE, disabled: false, **system_arguments) @icon = icon @show_tooltip = show_tooltip @system_arguments = system_arguments @system_arguments[:id] ||= self.class.generate_id @system_arguments[:disabled] = disabled @system_arguments[:classes] = class_names( "Button", "Button--iconOnly", SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME)], Primer::Beta::Button::SIZE_MAPPINGS[fetch_or_fallback(Primer::Beta::Button::SIZE_OPTIONS, size, Primer::Beta::Button::DEFAULT_SIZE)], system_arguments[:classes] ) validate_aria_label @aria_label = aria("label", @system_arguments) @aria_description = aria("description", @system_arguments) return unless render_tooltip? @tooltip_arguments = { for_id: @system_arguments[:id], direction: tooltip_direction } # If we have both an `aria-label` and a `aria-description`, we create a `Tooltip` with the description type and keep the `aria-label` in the button. # Otherwise, the `aria-label` is used as the tooltip text, which is the `aria-labelled-by` of the button, so we don't set it in the button. if @aria_label.present? && @aria_description.present? @system_arguments.delete(:"aria-description") @system_arguments[:aria].delete(:description) if @system_arguments.include?(:aria) @tooltip_arguments[:text] = @aria_description @tooltip_arguments[:type] = :description else @system_arguments.delete(:"aria-label") @system_arguments[:aria].delete(:label) if @system_arguments.include?(:aria) @tooltip_arguments[:text] = @aria_label @tooltip_arguments[:type] = :label end @tooltip = Primer::Alpha::Tooltip.new(**@tooltip_arguments) aria_key = @tooltip_arguments[:type] == :label ? :labelledby : :describedby @system_arguments[:aria] = merge_aria( @system_arguments, { aria: { aria_key => @tooltip.id } } ) end
def render_tooltip?
def render_tooltip? @show_tooltip && @system_arguments[:tag] != :summary end