Tooltips ​

The tooltip component shows a short description alongside a button. Use it for supplemental information and keep essential instructions visible on the page.

Base classes ​

Wrap the description and its button in .tooltip. Use .tooltip-description for the text and .tooltip-toggle on a button with an accessible name. Initialization gives the description the tooltip role and associates it with the button through aria-describedby.

By default, the tooltip opens when you hover over the button or Tab to it. Click the button or press Enter or Space to toggle it. Press Escape to close it.

Note

The preview limits the description width so it fits beside the button on narrow screens.

Initialization ​

Run the tooltip generator after the markup is in the DOM.

js
import generateTooltips from "@graupl/core/tooltip/generator";

generateTooltips();

Variants ​

By default, no theme variants are generated.

If you are compiling your own version of Graupl, you can set the tooltip module’s $themeable variable to true to generate the .primary, .secondary, and .tertiary variants.

Custom Properties ​

The following custom properties can be used to customize the tooltip component:

PropertyDescriptionDefault Value
--graupl-tooltip-padding-xThe horizontal padding of the tooltip.var(--graupl-spacer-0)
--graupl-tooltip-padding-yThe vertical padding of the tooltip.var(--graupl-spacer-0)
--graupl-tooltip-paddingThe padding of the tooltip.var(--graupl-tooltip-padding-y) var(--graupl-tooltip-padding-x)
--graupl-tooltip-displayThe display of the tooltip.inline
--graupl-tooltip-widthThe width of the tooltip.fit-content
--graupl-tooltip-backgroundThe background of the tooltip.var(--graupl-background)
--graupl-tooltip-colorThe color of the tooltip.var(--graupl-color)
--graupl-tooltip-border-colorThe border color of the tooltip.var(--graupl-tooltip-color)
--graupl-tooltip-border-top-left-radiusThe border top left radius of the tooltip.var(--graupl-border-top-left-radius)
--graupl-tooltip-border-top-right-radiusThe border top right radius of the tooltip.var(--graupl-border-top-right-radius)
--graupl-tooltip-border-bottom-left-radiusThe border bottom left radius of the tooltip.var(--graupl-border-bottom-left-radius)
--graupl-tooltip-border-bottom-right-radiusThe border bottom right radius of the tooltip.var(--graupl-border-bottom-right-radius)
--graupl-tooltip-border-radiusThe border radius of the tooltip.var(--graupl-tooltip-border-top-left-radius) var(--graupl-tooltip-border-top-right-radius) var(--graupl-tooltip-border-bottom-right-radius) var(--graupl-tooltip-border-bottom-left-radius)
--graupl-tooltip-border-top-widthThe border top width of the tooltip.0
--graupl-tooltip-border-right-widthThe border right width of the tooltip.0
--graupl-tooltip-border-bottom-widthThe border bottom width of the tooltip.0
--graupl-tooltip-border-left-widthThe border left width of the tooltip.0
--graupl-tooltip-border-widthThe border width of the tooltip.var(--graupl-tooltip-border-top-width) var(--graupl-tooltip-border-right-width) var(--graupl-tooltip-border-bottom-width) var(--graupl-tooltip-border-left-width)
--graupl-tooltip-border-top-styleThe border top style of the tooltip.var(--graupl-border-top-style)
--graupl-tooltip-border-right-styleThe border right style of the tooltip.var(--graupl-border-right-style)
--graupl-tooltip-border-bottom-styleThe border bottom style of the tooltip.var(--graupl-border-bottom-style)
--graupl-tooltip-border-left-styleThe border left style of the tooltip.var(--graupl-border-left-style)
--graupl-tooltip-border-styleThe border style of the tooltip.var(--graupl-tooltip-border-top-style) var(--graupl-tooltip-border-right-style) var(--graupl-tooltip-border-bottom-style) var(--graupl-tooltip-border-left-style)
--graupl-tooltip-description-widthThe width of the tooltip description.30ch
--graupl-tooltip-description-colorThe color of the tooltip description.var(--graupl-tooltip-color)
--graupl-tooltip-description-backgroundThe background of the tooltip description.var(--graupl-tooltip-background)
--graupl-tooltip-description-font-sizeThe tooltip description font size.inherit
--graupl-tooltip-description-font-weightThe font weight of the tooltip description.var(--graupl-root-font-weight)
--graupl-tooltip-description-font-familyThe font family of the tooltip description.var(--graupl-root-font-family)
--graupl-tooltip-description-line-heightThe line height of the tooltip description.var(--graupl-root-line-height)
--graupl-tooltip-description-marginThe margin of the tooltip description.0 0 0 0
--graupl-tooltip-description-padding-xThe horizontal padding of the tooltip description.var(--graupl-spacer-3)
--graupl-tooltip-description-padding-yThe vertical padding of the tooltip description.var(--graupl-spacer-2)
--graupl-tooltip-description-paddingThe padding of the tooltip description.var(--graupl-tooltip-description-padding-y) var(--graupl-tooltip-description-padding-x)
--graupl-tooltip-description-indentThe indent of the tooltip description.calc(var(--graupl-tooltip-toggle-width) + var(--graupl-spacer-2))
--graupl-tooltip-description-topThe top inset of the tooltip description.auto
--graupl-tooltip-description-rightThe right inset of the tooltip description.auto
--graupl-tooltip-description-bottomThe bottom inset of the tooltip description.auto
--graupl-tooltip-description-leftThe left inset of the tooltip description.var(--graupl-tooltip-description-indent)
--graupl-tooltip-description-insetThe inset of the tooltip description.var(--graupl-tooltip-description-top) var(--graupl-tooltip-description-right) var(--graupl-tooltip-description-bottom) var(--graupl-tooltip-description-left)
--graupl-tooltip-description-border-colorThe border color of the tooltip description.var(--graupl-tooltip-border-color)
--graupl-tooltip-description-border-top-left-radiusThe border top left radius of the tooltip description.var(--graupl-border-top-left-radius)
--graupl-tooltip-description-border-top-right-radiusThe border top right radius of the tooltip description.var(--graupl-border-top-right-radius)
--graupl-tooltip-description-border-bottom-left-radiusThe border bottom left radius of the tooltip description.var(--graupl-border-bottom-left-radius)
--graupl-tooltip-description-border-bottom-right-radiusThe border bottom right radius of the tooltip description.var(--graupl-border-bottom-right-radius)
--graupl-tooltip-description-border-radiusThe border radius of the tooltip description.var(--graupl-tooltip-description-border-top-left-radius) var(--graupl-tooltip-description-border-top-right-radius) var(--graupl-tooltip-description-border-bottom-right-radius) var(--graupl-tooltip-description-border-bottom-left-radius)
--graupl-tooltip-description-border-top-widthThe border top width of the tooltip description.var(--graupl-border-top-width)
--graupl-tooltip-description-border-right-widthThe border right width of the tooltip description.var(--graupl-border-right-width)
--graupl-tooltip-description-border-bottom-widthThe border bottom width of the tooltip description.var(--graupl-border-bottom-width)
--graupl-tooltip-description-border-left-widthThe border left width of the tooltip description.var(--graupl-border-left-width)
--graupl-tooltip-description-border-widthThe border width of the tooltip description.var(--graupl-tooltip-description-border-top-width) var(--graupl-tooltip-description-border-right-width) var(--graupl-tooltip-description-border-bottom-width) var(--graupl-tooltip-description-border-left-width)
--graupl-tooltip-description-border-top-styleThe border top style of the tooltip description.var(--graupl-border-top-style)
--graupl-tooltip-description-border-right-styleThe border right style of the tooltip description.var(--graupl-border-right-style)
--graupl-tooltip-description-border-bottom-styleThe border bottom style of the tooltip description.var(--graupl-border-bottom-style)
--graupl-tooltip-description-border-left-styleThe border left style of the tooltip description.var(--graupl-border-left-style)
--graupl-tooltip-description-border-styleThe border style of the tooltip description.var(--graupl-tooltip-description-border-top-style) var(--graupl-tooltip-description-border-right-style) var(--graupl-tooltip-description-border-bottom-style) var(--graupl-tooltip-description-border-left-style)
--graupl-tooltip-toggle-widthThe width of the tooltip toggle.var(--graupl-button-min-width)
--graupl-tooltip-toggle-heightThe height of the tooltip toggle.var(--graupl-button-min-height)
--graupl-tooltip-toggle-contentThe content of the tooltip toggle."i"
--graupl-tooltip-toggle-font-familyThe font family of the tooltip toggle.serif
--graupl-tooltip-toggle-font-sizeThe font size of the tooltip toggle.var(--graupl-font-size-sm)
--graupl-tooltip-toggle-font-weightThe font weight of the tooltip toggle.var(--graupl-font-weight-bold)
--graupl-tooltip-toggle-padding-xThe horizontal padding of the tooltip toggle.var(--graupl-spacer-1)
--graupl-tooltip-toggle-padding-yThe vertical padding of the tooltip toggle.var(--graupl-spacer-1)
--graupl-tooltip-toggle-paddingThe padding of the tooltip toggle.var(--graupl-tooltip-toggle-padding-y) var(--graupl-tooltip-toggle-padding-x)
--graupl-tooltip-toggle-border-top-left-radiusThe border top left radius of the tooltip toggle.100vw
--graupl-tooltip-toggle-border-top-right-radiusThe border top right radius of the tooltip toggle.100vw
--graupl-tooltip-toggle-border-bottom-left-radiusThe border bottom left radius of the tooltip toggle.100vw
--graupl-tooltip-toggle-border-bottom-right-radiusThe border bottom right radius of the tooltip toggle.100vw
--graupl-tooltip-toggle-border-radiusThe border radius of the tooltip toggle.var(--graupl-tooltip-toggle-border-top-left-radius) var(--graupl-tooltip-toggle-border-top-right-radius) var(--graupl-tooltip-toggle-border-bottom-right-radius) var(--graupl-tooltip-toggle-border-bottom-left-radius)
--graupl-tooltip-toggle-backgroundThe background of the tooltip toggle.var(--graupl-tooltip-background)
--graupl-tooltip-toggle-visited-backgroundThe visited background of the tooltip toggle.var(--graupl-tooltip-toggle-background)
--graupl-tooltip-toggle-focus-backgroundThe focus background of the tooltip toggle.var(--graupl-tooltip-toggle-background)
--graupl-tooltip-toggle-hover-backgroundThe hover background of the tooltip toggle.var(--graupl-tooltip-color)
--graupl-tooltip-toggle-active-backgroundThe active background of the tooltip toggle.var(--graupl-tooltip-toggle-hover-background)
--graupl-tooltip-toggle-selected-backgroundThe selected background of the tooltip toggle.var(--graupl-tooltip-toggle-hover-background)
--graupl-tooltip-toggle-disabled-backgroundThe disabled background of the tooltip toggle.var(--graupl-tooltip-background)
--graupl-tooltip-toggle-colorThe color of the tooltip toggle.var(--graupl-tooltip-color)
--graupl-tooltip-toggle-visited-colorThe visited color of the tooltip toggle.var(--graupl-tooltip-toggle-color)
--graupl-tooltip-toggle-focus-colorThe focus color of the tooltip toggle.var(--graupl-tooltip-toggle-color)
--graupl-tooltip-toggle-hover-colorThe hover color of the tooltip toggle.var(--graupl-tooltip-background)
--graupl-tooltip-toggle-active-colorThe active color of the tooltip toggle.var(--graupl-tooltip-toggle-hover-color)
--graupl-tooltip-toggle-selected-colorThe selected color of the tooltip toggle.var(--graupl-tooltip-toggle-hover-color)
--graupl-tooltip-toggle-disabled-colorThe disabled color of the tooltip toggle.var(--graupl-theme-active--primary--200)
--graupl-tooltip-toggle-border-colorThe border color of the tooltip toggle.var(--graupl-tooltip-border-color)
--graupl-tooltip-toggle-visited-border-colorThe visited border color of the tooltip toggle.var(--graupl-tooltip-toggle-border-color)
--graupl-tooltip-toggle-focus-border-colorThe focus border color of the tooltip toggle.var(--graupl-tooltip-toggle-border-color)
--graupl-tooltip-toggle-hover-border-colorThe hover border color of the tooltip toggle.var(--graupl-tooltip-border-color)
--graupl-tooltip-toggle-active-border-colorThe active border color of the tooltip toggle.var(--graupl-tooltip-toggle-hover-border-color)
--graupl-tooltip-toggle-selected-border-colorThe selected border color of the tooltip toggle.var(--graupl-tooltip-toggle-hover-border-color)
--graupl-tooltip-toggle-disabled-border-colorThe disabled border color of the tooltip toggle.var(--graupl-theme-active--primary--200)
--graupl-tooltip-toggle-transformThe transform of the tooltip toggle.none
--graupl-tooltip-toggle-visited-transformThe visited transform of the tooltip toggle.var(--graupl-tooltip-toggle-transform)
--graupl-tooltip-toggle-focus-transformThe focus transform of the tooltip toggle.var(--graupl-tooltip-toggle-transform)
--graupl-tooltip-toggle-hover-transformThe hover transform of the tooltip toggle.var(--graupl-tooltip-toggle-transform)
--graupl-tooltip-toggle-active-transformThe active transform of the tooltip toggle.none
--graupl-tooltip-toggle-selected-transformThe selected transform of the tooltip toggle.none
--graupl-tooltip-toggle-disabled-transformThe disabled transform of the tooltip toggle.none

Sass variables ​

The following Sass variables can be used to customize the generation of the tooltip component:

VariableDescriptionDefault Value
$selector-baseDefault for selector base."."
$modifier-selector-baseDefault for modifier selector base."."
$generate-base-theme-mapDefault for generate base theme map.true
$themeableDefault for themeable.false
$tooltip-selector-baseDefault for tooltip selector base."."
$tooltip-selectorDefault for tooltip selector."tooltip"
$tooltip-theme-selector-baseDefault for tooltip theme selector base."."
$tooltip-theme-selector-prefixDefault for tooltip theme selector prefix.""
$tooltip-toggle-selector-baseDefault for tooltip button selector base."."
$tooltip-toggle-selectorDefault for tooltip button selector."tooltip-toggle"
$tooltip-description-selector-baseDefault for tooltip description selector base."."
$tooltip-description-selectorDefault for tooltip description selector."tooltip-description"
$tooltip-hidden-selector-baseDefault for tooltip hidden selector base."."
$tooltip-hidden-selectorDefault for tooltip hidden selector."hide"
$tooltip-shown-selector-baseDefault for tooltip shown selector base."."
$tooltip-shown-selectorDefault for tooltip shown selector."show"
$tooltip-transitioning-selector-baseDefault for tooltip transitioning selector base."."
$tooltip-transitioning-selectorDefault for tooltip transitioning selector."transitioning"
$tooltip-theme-mappingsDefault for tooltip theme mappings.()
$tooltip-theme-mapDefault for tooltip theme map.()
$tooltip-toggle-initial-transformDefault for tooltip toggle initial transform.none
$tooltip-toggle-final-transformDefault for tooltip toggle final transform.none
$tooltip-toggle-disabled-transformDefault for tooltip toggle disabled transform.$tooltip-toggle-initial-transform
$tooltip-displayDefault for tooltip display.inline
$tooltip-widthDefault for tooltip width.fit-content
$tooltip-description-widthDefault for tooltip description width.30ch