Tooltip
A tooltip is a brief, informative message that appears when a user interacts with an element.
import {QTooltip, QTooltipContent, QTooltipTrigger} from "@qui/react"
Overview
QUI exports 3 tooltip related components:
QTooltip
: provides context and state for the tooltip.QTooltipContent
: should contain the content of the tooltip.QTooltipTrigger
: the element that activates the tooltip and serves as the tooltip's anchor.
Examples
Showcase
The default trigger for the tooltip is hover or focus. You can manually control the state for additional customization.
import {ReactNode, useState} from "react"import {QButton, QTooltip, QTooltipContent, QTooltipTrigger} from "@qui/react"export default function Showcase(): ReactNode {const [open, setOpen] = useState(false)return (<div className="grid justify-center gap-4"><QTooltip><QTooltipTrigger><QButton color="primary" variant="fill">Hover or Focus</QButton></QTooltipTrigger><QTooltipContent>Tooltip Content</QTooltipContent></QTooltip><QTooltip open={open}><QTooltipTrigger><QButtoncolor="primary"onClick={() => setOpen((prevState) => !prevState)}variant="fill">Click</QButton></QTooltipTrigger><QTooltipContent>Tooltip Content</QTooltipContent></QTooltip></div>)}
Arrow
Use the arrow input to show an arrow between the tooltip and its anchor element.
import {ReactNode} from "react"import {QButton, QTooltip, QTooltipContent, QTooltipTrigger} from "@qui/react"export default function Arrow(): ReactNode {return (<div className="grid justify-center"><QTooltip arrow><QTooltipTrigger><QButton color="primary" variant="fill">Hover or Focus</QButton></QTooltipTrigger><QTooltipContent>Tooltip Content</QTooltipContent></QTooltip></div>)}
Placement
Control the anchor origin of the tooltip using the placement property.
API
QTooltip
Name & Description | Option(s) | Default |
---|---|---|
The CSS transition-duration of the enter and exit animations. Supply as a
number to configure both transitions at once, or supply an object to configure
the enter and exit transitions independently. |
| 250 |
Show an arrow between the component and the anchor element. |
| true |
Configure the element shown when arrow is true . |
| |
Ensure that the component remains anchored to its reference element following
screen resizes or position changes. |
| |
ReactNode | ||
The default value when uncontrolled. |
| |
Box shadow severity of the panel, based on the five elevation styles provided
by QDS. A higher number means a more severe box shadow. Supply 0 to disable
the box shadow. |
| |
Whether to flip the component's placement to keep it in view. |
| true |
| true | |
| true | |
The controlled id of the component. If not provided, a value will be used as
a fallback. |
| |
The distance between the tooltip and its anchor element. |
| 5 |
Callback fired when panel visibility changes.
|
| |
The controlled state for the tooltip. Supplying this value will override
hover and focus events. |
| |
Describes the placement of the component before FloatingUI has applied all the
modifiers that may have flipped or altered the component. The final placement
may differ from this input property. |
| 'top' |
CSS position attribute of the component. Can be "absolute" or "fixed". |
| 'absolute' |
| 1080 |
Type
| number| {enter: numberexit: number}
Default
250
Description
The CSS transition-duration of the enter and exit animations. Supply as a
number to configure both transitions at once, or supply an object to configure
the enter and exit transitions independently.
Type
boolean
Default
true
Description
Show an arrow between the component and the anchor element.
Type
{className?: stringfill?: stringheight?: numberstyle?: CSSPropertieswidth?: number}
Description
Configure the element shown when arrow is
true
.Type
boolean
Description
Ensure that the component remains anchored to its reference element following
screen resizes or position changes.
Type
boolean
Description
The default value when uncontrolled.
Type
| 0| 1| 2| 3| 4| 5| '0'| '1'| '2'| '3'| '4'| '5'
Description
Box shadow severity of the panel, based on the five elevation styles provided
by QDS. A higher number means a more severe box shadow. Supply 0 to disable
the box shadow.
Type
boolean
Default
true
Description
Whether to flip the component's placement to keep it in view.
Type
boolean
Default
true
Description
If true, the tooltip will show when the anchor element is focused with the
keyboard and hide on blur. This property is ignored if open is
supplied.
Type
boolean
Default
true
Description
If true, the tooltip will show when the anchor element is hovered. This
property is ignored if open is supplied.
Type
string
Description
The controlled id of the component. If not provided, a value will be used as
a fallback.
Type
| number| {alignmentAxis?: numbercrossAxis?: numbermainAxis?: number}
Default
5
Description
The distance between the tooltip and its anchor element.
Type
(open: boolean,event?: Event,reason?:| 'ancestor-scroll'| 'click'| 'escape-key'| 'focus'| 'hover'| 'list-navigation'| 'outside-press'| 'reference-press'| 'safe-polygon',) => void
Description
Callback fired when panel visibility changes.
- openThe updated state.
- eventThe event that triggered the change.
- reasonThe cause of the change.
Type
boolean
Description
The controlled state for the tooltip. Supplying this value will override
hover and focus events.
Type
| 'top-start'| 'top'| 'top-end'| 'bottom-start'| 'bottom'| 'bottom-end'| 'left-start'| 'left'| 'left-end'| 'right-start'| 'right'| 'right-end'
Default
'top'
Description
Describes the placement of the component before FloatingUI has applied all the
modifiers that may have flipped or altered the component. The final placement
may differ from this input property.
Type
| 'absolute'| 'fixed'
Default
'absolute'
Description
CSS position attribute of the component. Can be "absolute" or "fixed".
QTooltipContent
Name & Description | Option(s) | Default |
---|---|---|
ReactNode | ||
The component used for the root node. It can be a React component or
element. |
| 'div' |
The className property of the Element
interface gets and sets the value of the
class attribute
of the specified element. |
| |
The style global attribute
contains CSS styling
declarations to be applied to the element. | CSSProperties |
Type
| ElementType| ComponentType
Default
'div'
Description
The component used for the root node. It can be a React component or
element.
Type
string
Description
The className property of the Element
interface gets and sets the value of the
class attribute
of the specified element.
Type
CSSProperties
Description
The style global attribute
contains CSS styling
declarations to be applied to the element.