Tooltip
Display information related to an element when the element receives keyboard focus or the mouse hovers over it.
import { Tooltip } from "@vitality-ds/components";
A Tooltip presents a brief, informative message that appears when a user interacts with an element. It is usually initiated either through a mouse-hover gesture or when the element recieves focus via the keyboard. It is not focusable and cannot contain focusable content.
Use the Tooltip
component to wrap the component you wish to trigger the tooltip, then pass the tooltip's content via the content
prop.
<Tooltip content="Add Diagnostic Request (⌘+R)"> <Button> <Request /> Add </Button> </Tooltip>
- Provide brief and helpful content inside the tooltip. If you can't think of particularly helpful content, don't offer a tooltip
- Provide additional explanation for a form field unfamiliar to some users or reasoning for what may seem like an unusual request.
- Provide tooltips for unlabeled icons and IconButtons
- Users shouldn't need to find a tooltip in order to complete their task.
- Don't add redundant content - it should be adding value.
- Avoid hiding medically-critical information inside tooltips.
Aim to keep tooltips short and to the point. To handle larger amounts of content, the tooltip has a maxiumum width set and text will wrap over multiple lines. Tooltips are not interactive, nor can they handle rich content. Consider using a Popover component if you need this functionality.
<Tooltip content="This is a Patient Claim. Any correspondence from Medicare / Fund are sent directly to the patient."> <Button>Multi-line content</Button> </Tooltip>
As all tooltips are "collision-aware", their position will change depending on the space available in the viewport. You can however decide on their "preferred" position.
Setting the preferredSide
property determines the preferred side against the trigger that the tooltip should be placed. The side will change to its opposite when collisions occur.
Setting the preferredAlignment
property determines the position relative to the preferred side and changes the placement of the small arrow outside the tooltip. The side will change to its opposite when collisions occur.
Not applicable
If the Tooltip is wrapping a functional component, ensure that the functional component accepts a ref using forwardRef.
() => { const MyButton = React.forwardRef((props, forwardedRef) => ( <button ref={forwardedRef} {...props}> Button </button> )); return ( <Tooltip content="This is a Patient Claim. Any correspondence from Medicare / Fund are sent directly to the patient."> <MyButton /> </Tooltip> ); };
Description
If the content within the tooltip is not descriptive enough or you have content that cannot be read by a screen reader, use aria-label as a more descriptive label. By default, screenreaders will announce the content inside the component.
Type
string
Description
Element that triggers the tooltip when it receives keyboard focus or the mouse hovers it. React elements need to have refs forwarded to them.
Type
ReactNode
Description
The contents of the tooltip itself. For simple contents, pass a string. For multiline contents or rich text, pass a React component / JSX.
Type
ReactNode
Description
The open state of the tooltip.
Type
boolean
Description
Event handler called when the open state of the tooltip changes.
Type
(open: boolean) => void
Description
The preferred alignment against the trigger. May change when collisions occur.
Type
"start" | "center" | "end"
Default Value
center
Description
` The preferred side of the child element to align the tooltip against when open. Will be reversed when collisions occur.
Type
"top" | "right" | "bottom" | "left"
Default Value
top
Description
Optionally hide the arrow.
Type
boolean
Default Value