Class: Primer::Alpha::Tooltip
- Defined in:
- app/components/primer/alpha/tooltip.rb
Overview
‘Tooltip` only appears on mouse hover or keyboard focus and contain a label or description text. Use tooltips sparingly and as a last resort.
When using a tooltip, follow the provided guidelines to avoid accessibility issues.
-
Tooltip text should be brief and to the point. The tooltip content must be a string.
-
Tooltips should contain only **non-essential text**. Tooltips can easily be missed and are not accessible on touch devices so never
use tooltips to convey critical information.
Constant Summary collapse
- DIRECTION_DEFAULT =
:s- DIRECTION_OPTIONS =
[DIRECTION_DEFAULT, :n, :e, :w, :ne, :nw, :se, :sw].freeze
- TYPE_FALLBACK =
:description- TYPE_OPTIONS =
[:label, :description].freeze
Constants inherited from Component
Component::INVALID_ARIA_LABEL_TAGS
Constants included from Status::Dsl
Constants included from ViewHelper
Constants included from TestSelectorHelper
TestSelectorHelper::TEST_SELECTOR_TAG
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::InvalidValueError
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(type:, for_id:, text:, direction: DIRECTION_DEFAULT, **system_arguments) ⇒ Tooltip
constructor
A new instance of Tooltip.
Methods included from JoinStyleArgumentsHelper
Methods included from TestSelectorHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?
Methods included from ClassNameHelper
Constructor Details
#initialize(type:, for_id:, text:, direction: DIRECTION_DEFAULT, **system_arguments) ⇒ Tooltip
Returns a new instance of Tooltip.
78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/components/primer/alpha/tooltip.rb', line 78 def initialize(type:, for_id:, text:, direction: DIRECTION_DEFAULT, **system_arguments) raise TypeError, "tooltip text must be a string" unless text.is_a?(String) @text = text @system_arguments = system_arguments @system_arguments[:hidden] = true @system_arguments[:tag] = :"tool-tip" @system_arguments[:for] = for_id @system_arguments[:"data-direction"] = fetch_or_fallback(DIRECTION_OPTIONS, direction, DIRECTION_DEFAULT).to_s @system_arguments[:"data-type"] = fetch_or_fallback(TYPE_OPTIONS, type, TYPE_FALLBACK).to_s end |
Instance Method Details
#call ⇒ Object
90 91 92 |
# File 'app/components/primer/alpha/tooltip.rb', line 90 def call render(Primer::BaseComponent.new(**@system_arguments)) { @text } end |