Tooltip

Tooltips are very useful to communicate extra information related to an element on the screen. The information should be contextual, useful, and nonessential.

Import

import { Tooltip } from '@contentful/f36-components';
// or
import { Tooltip } from '@contentful/f36-tooltip';

Examples

Button with tooltip

function ButtonWithTooltipExample() {
return (
<Tooltip placement="top" id="tooltip-1" content="This feature is disabled.">
<Button isDisabled>Update</Button>
</Tooltip>
);
}

Tooltips in Text

function TooltipInTextExample() {
const TextWithNote = ({ note, id, children }) => (
<Tooltip placement="top" id={id} content={note}>
<Text as="b" fontColor="red600" fontWeight="fontWeightDemiBold">
{children}
</Text>
</Tooltip>
);
return (
<Text as="p">
A{' '}
<TextWithNote note="Content Management System" id="cms">
CMS
</TextWithNote>{' '}
is a{' '}
<TextWithNote
note="A collection of instructions to tell a computer how to work."
id="software"
>
computer software
</TextWithNote>{' '}
used to manage the creation and modification of digital content.
</Text>
);
}

Tooltip without wrapper (withTriggerWrapper={false})

  • Use withTriggerWrapper={false} to avoid rendering an additional wrapper element around the trigger.
  • withTriggerWrapper={false} requires a single valid React element as children.
  • as and targetWrapperClassName only apply when the trigger wrapper is enabled.
  • If the trigger element is disabled, the tooltip will not be shown on hover in this mode.
function WithoutTriggerWrapperTooltipExample() {
return (
<Tooltip
withTriggerWrapper={false}
content="I am rendered without an extra wrapper"
>
<TextLink href="/">Hover me</TextLink>
</Tooltip>
);
}

Props (API reference)

Open in Storybook

Name

Type

Default

children
required
ReactNode

Child nodes to be rendered as the trigger of the tooltip component. The tooltip will be displayed on hover or focus of the child element

as
"a"
"abbr"
"address"
"animate"
"animateMotion"
"animateTransform"
"area"
"article"
"aside"
"audio"
"b"
"base"
"bdi"
"bdo"
"big"
"blockquote"
"body"
"br"
"button"
"canvas"
"caption"
"center"
"circle"
"cite"
"clipPath"
"code"
"col"
"colgroup"
"data"
"datalist"
"dd"
"defs"
"del"
"desc"
"details"
"dfn"
"dialog"
"div"
"dl"
"dt"
"ellipse"
"em"
"embed"
"feBlend"
"feColorMatrix"
"feComponentTransfer"
"feComposite"
"feConvolveMatrix"
"feDiffuseLighting"
"feDisplacementMap"
"feDistantLight"
"feDropShadow"
"feFlood"
"feFuncA"
"feFuncB"
"feFuncG"
"feFuncR"
"feGaussianBlur"
"feImage"
"feMerge"
"feMergeNode"
"feMorphology"
"feOffset"
"fePointLight"
"feSpecularLighting"
"feSpotLight"
"feTile"
"feTurbulence"
"fieldset"
"figcaption"
"figure"
"filter"
"footer"
"foreignObject"
"form"
"g"
"h1"
"h2"
"h3"
"h4"
"h5"
"h6"
"head"
"header"
"hgroup"
"hr"
"html"
"i"
"iframe"
"image"
"img"
"input"
"ins"
"kbd"
"keygen"
"label"
"legend"
"li"
"line"
"linearGradient"
"link"
"main"
"map"
"mark"
"marker"
"mask"
"menu"
"menuitem"
"meta"
"metadata"
"meter"
"mpath"
"nav"
"noindex"
"noscript"
"object"
"ol"
"optgroup"
"option"
"output"
"p"
"param"
"path"
"pattern"
"picture"
"polygon"
"polyline"
"pre"
"progress"
"q"
"radialGradient"
"rect"
"rp"
"rt"
"ruby"
"s"
"samp"
"script"
"search"
"section"
"select"
"set"
"slot"
"small"
"source"
"span"
"stop"
"strong"
"style"
"sub"
"summary"
"sup"
"svg"
"switch"
"symbol"
"table"
"tbody"
"td"
"template"
"text"
"textarea"
"textPath"
"tfoot"
"th"
"thead"
"time"
"title"
"tr"
"track"
"tspan"
"u"
"ul"
"use"
"var"
"video"
"view"
"wbr"
"webview"
ComponentClass<any, any>
FunctionComponent<any>

HTML element used to wrap the target of the tooltip

span
className
string

CSS class to be appended to the root element

content
string
ReactElement<unknown, string | JSXElementConstructor<any>>

Content of the tooltip

hideDelay
number

Set a delay period in milliseconds before hiding the tooltip

0
id
string

A unique id of the tooltip

isDisabled
false
true

Prevents showing the tooltip

false
isVisible
false
true

It controls the initial visibility of the tooltip

false
label
string

Accessible label property, only required when using a ReactElement as content

maxWidth
number
"-moz-initial"
"inherit"
"initial"
"revert"
"revert-layer"
"unset"
"-moz-fit-content"
"-moz-max-content"
"-moz-min-content"
"-webkit-fit-content"
"-webkit-max-content"
"-webkit-min-content"
"fit-content"
"intrinsic"
"max-content"
"min-content"
"none"
string & {}

It sets a max-width for the tooltip

240
onBlur
(evt: FocusEvent<Element, Element>) => void

Function that will be called when target gets blurred

onFocus
(evt: FocusEvent<Element, Element>) => void

Function that will be called when target gets focused

onKeyDown
(evt: KeyboardEvent<HTMLSpanElement>) => void

Function that will be called when the user uses a keyboard key on the target

onMouseLeave
(evt: MouseEvent<Element, MouseEvent>) => void

Function that will be called when the user move the mouse out of the target

onMouseOver
(evt: MouseEvent<Element, MouseEvent>) => void

Function that will be called when the user move the mouse over of the target

placement
"top"
"right"
"bottom"
"left"
"top-start"
"top-end"
"right-start"
"right-end"
"bottom-start"
"bottom-end"
"left-start"
"left-end"
"auto"

It sets the "preferred" position of the tooltip

showDelay
number

Set a delay period in milliseconds before showing the tooltip

375
targetWrapperClassName
string

Class names to be appended to the className prop of the tooltip’s target wrapper

testId
string

A [data-test-id] attribute used for testing purposes

cf-ui-tooltip
usePortal
false
true

Boolean to control whether or not to render the tooltip in a React Portal. Rendering content inside a Portal allows the tooltip to escape the bounds of its parent while still being positioned correctly. Using a Portal is necessary if an ancestor of the tooltip hides overflow. Defaults to `false`

false
withTriggerWrapper
false
true

Whether the trigger should be wrapped in an element.

true

Content guidelines

  • Use a short label or explanation. Aim for one line and keep explanations to roughly two lines.
  • Use Caption/Normal typography: 12px regular text with a 16px line height.
  • Text aligns to the reading direction and wraps naturally within a default maximum width of 240px. Avoid manual line breaks or truncating tooltip text. Use maxWidth only when the content requires a different width.
  • Use React elements only for minimal inline formatting, such as emphasis. Provide an accessible label when using React elements.
  • Use a Popover for headings, multiple paragraphs, images, links, buttons, or other interactive content. Keep essential instructions visible in the interface.

Accessibility

  • Do not put essential information in Tooltip component
  • Add unique id property to the tooltip, so appropriate a11y attributes could be used.
<Tooltip placement="top" id="tooltip" content="Hi I am a Tooltip">
<TextLink>Hover me</TextLink>
</Tooltip>