class Primer::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.
`“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, box: false, tooltip_direction: Primer::Alpha::Tooltip::DIRECTION_DEFAULT, **system_arguments)
-
system_arguments(Hash) -- <%= link_to_system_arguments_docs %> -
box(Boolean) -- Whether the button is in a <%= link_to_component(Primer::Beta::BorderBox) %>. If `true`, the button will have the `Box-btn-octicon` class. -
tooltip_direction(Symbol) -- (Primer::Alpha::Tooltip::DIRECTION_DEFAULT) <%= one_of(Primer::Alpha::Tooltip::DIRECTION_OPTIONS) %> -
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) %> -
tag(Symbol) -- <%= one_of(Primer::Beta::BaseButton::TAG_OPTIONS) %> -
icon(String) -- Name of <%= link_to_octicons %> to use. -
scheme(Symbol) -- <%= one_of(Primer::IconButton::SCHEME_OPTIONS) %>
Other tags:
- Example: Custom tooltip direction -
Example: With an `aria-description` -
Example: In a BorderBox -
Example: Schemes -
Example: Default -
def initialize(icon:, scheme: DEFAULT_SCHEME, box: false, tooltip_direction: Primer::Alpha::Tooltip::DIRECTION_DEFAULT, **system_arguments) @icon = icon @system_arguments = system_arguments @system_arguments[:id] ||= "icon-button-#{SecureRandom.hex(4)}" @system_arguments[:classes] = class_names( "btn-octicon", SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME)], system_arguments[:classes], "Box-btn-octicon" => box ) validate_aria_label @aria_label = aria("label", @system_arguments) @aria_description = aria("description", @system_arguments) @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 end
def render_tooltip?
def render_tooltip? @system_arguments[:tag] != :summary end