Tooltips

Informative tooltips that render on mouse over.

javascript
import { tooltip } from '@brainandbones/skeleton';
javascript
// Included in 'all.css' and 'elements.css'
import '@brainandbones/skeleton/styles/elements/tooltips.css';

Usage

Use the tooltip action and provided your desired content. Note that content does support HTML.

html
<button use:tooltip={{ content: 'Skeleton' }}>Trigger</button>

This will automatically construct and wrap the target element with the required markup.

html
<!-- Container -->
<span class="tooltip-container relative regionContainer">
	<!-- Tooltip -->
	<div class="tooltip tooltip-top regionTooltip hidden" role="tooltip" data-testid="tooltip">
		Skeleton
		<!-- Arrow -->
		<div class="tooltip-arrow-top regionArrow" />
	</div>
	<!-- Trigger -->
	<button>Trigger</button>
</span>

Positions

Adjust the setting for position: 'top|bottom|left|right'

html
<button use:tooltip={{ content: 'Skeleton', position: 'bottom' }}>Trigger</button>

Style Keys

Most styles should be handled via global CSS overrides. However, you may override styles using preset keys, similar to component props.

html
<button use:tooltip={{ ... background: '!bg-accent-500', text: '!text-yellow-500', width: '!w-56' }}>Trigger</button>

Style Region Keys

Use style regions to pass multiple abitrary classes to a particular element.

html
<button use:tooltip={{ ... regionTooltip: 'space-y-4 uppercase' }}>Trigger</button>

Action Params

Param styles should only be used for updating a single tooltip instance.

Prop Type Default Values Required Description
contentstring(tooltip)HTMLThe HTML content of your tooltip.
positionstringtoptop | bottom | left | right-Designates where the tooltip will appear.
inlinebooleanfalsetrue | false-Sets the wrapping element to inline or block.
backgroundstring-class-Provide a class to set the background color.
colorstring-class-Provide a class to set the text color.
widthstring-class-Provide a class to set the width.
paddingstring-class-Provide a class to set the padding.
shadowstring-class-Provide a class to set the box shadow.
roundedstring-class-Provide a class to set the border radius.
regionContainerstring-class-Provide arbitrary classes to the container element.
regionTooltipstring-class-Provide arbitrary classes to the tooltip element.
regionArrowstring-class-Provide arbitrary classes to the tooltip arrow element.

Classes

In most cases you should override Tooltip styles globally using these selectors.

Selector Description
.tooltip-containerThe wrapping DIV container.
.tooltipThe tooltip element body.
.tooltip-arrowThe small tooltip arrow.

Accessibility

Note the the ARIA Guidelines are a work-in-progress and subject to change over time.

Keyboard Interactions

Key Description
EscCloses all open tooltips.