Tooltips are very useful to communicate extra information related to an element on the screen. The information should be contextual, useful, and nonessential.
How to use Tooltip
- Even though it's possible to pass any ReactNode as a content of the Tooltip, we do not recommend passing very complex components try to use only Phrasing content
Code examples
Content guidelines
- Use short and clear messages as the
Tooltip
’s content
Accessibility
- Do not put essential information in
Tooltip
component - Add unique
id
property to the tooltip, so appropriate a11y attributes could be used.
Props
- Name
children(required)
DescriptionChild nodes to be rendered in the component and that will show the tooltip when they are hovered
ReactNode - Name
as
DescriptionHTML element used to wrap the target of the tooltip
HTML Tag or React Component (e.g. div, span, etc) - Name
className
DescriptionCSS class to be appended to the root element
string - Name
content
DescriptionContent of the tooltip
string - Name
hideDelay
DescriptionIt sets a delay period for the tooltip
Defaultnumber0 - Name
id
DescriptionA unique id of the tooltip
string - Name
isDisabled
DescriptionPrevents showing the tooltip
Defaultfalsetruefalse - Name
isVisible
DescriptionIt controls the initial visibility of the tooltip
falsetrue - Name
maxWidth
DescriptionIt sets a max-width for the tooltip
Defaultnumber"-moz-initial""inherit""initial""revert""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 & {}360 - Name
onBlur
DescriptionFunction that will be called when target gets blurred
(evt: FocusEvent<Element>) => void - Name
onFocus
DescriptionFunction that will be called when target gets focused
(evt: FocusEvent<Element>) => void - Name
onKeyDown
DescriptionFunction that will be called when the user uses a keyboard key on the target
(evt: KeyboardEvent) => void - Name
onMouseLeave
DescriptionFunction that will be called when the user move the mouse out of the target
(evt: MouseEvent<Element, MouseEvent>) => void - Name
onMouseOver
DescriptionFunction that will be called when the user move the mouse over of the target
(evt: MouseEvent<Element, MouseEvent>) => void - Name
placement
DescriptionIt sets the "preferred" position of the tooltip
Default"auto""auto-start""auto-end""top""bottom""right""left""top-start""top-end""bottom-start""bottom-end""right-start""right-end""left-start""left-end"auto - Name
targetWrapperClassName
DescriptionClass names to be appended to the className prop of the tooltip’s target
string - Name
testId
DescriptionA [data-test-id] attribute used for testing purposes
Defaultstringcf-ui-tooltip - Name
usePortal
DescriptionBoolean 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`
Defaultfalsetruefalse