Summer trip
Tooltips display brief labels or messages. Use them to add context to a button or another element while it is hovered or focused. A tooltip should not hold information that people cannot do without.
For information that people need, show it on the page, or in a dialog when it needs a response.
A tooltip is written with these parts:
| Part | Use |
|---|---|
TooltipTrigger | Wraps the element to describe and a Tooltip, with the element first. It opens the tooltip on a hover or keyboard focus. |
Tooltip | A plain tooltip (the default) or, with variant="rich", a rich tooltip |
PreviewTrigger | Wraps an element and a TooltipPopover, for a rich tooltip with actions |
TooltipPopover | A rich tooltip with buttons or links, in a PreviewTrigger, or in a DialogTrigger for a persistent rich tooltip |
import { PreviewTrigger, Tooltip, TooltipPopover, TooltipTrigger } from '@material-web/react'
import { Dialog, DialogTrigger, Focusable, Heading, Text } from 'react-aria-components'Basic tooltip
Wrap the element to describe and a Tooltip in a TooltipTrigger, the element first. Hover a button below, or move the focus to it with Tab.
import { Icon, IconButton, Tooltip, TooltipTrigger } from '@material-web/react'
const actions = [
['Add to favorites', 'star'],
['Share', 'share'],
['Download', 'download'],
['Delete', 'delete'],
] as const
export default function Basic() {
return (
<>
{actions.map(([label, icon]) => (
<TooltipTrigger key={label}>
<IconButton aria-label={label}>
<Icon name={icon} />
</IconButton>
<Tooltip>{label}</Tooltip>
</TooltipTrigger>
))}
</>
)
}The Tooltip comes in two variants: plain (the default) and rich. Set variant to choose one.
Plain tooltip
A plain tooltip briefly describes an element. Use it to label an element with no text, such as an icon button. Write a plain tooltip's text as its children. Text wider than 200dp wraps onto more lines.
import { Icon, IconButton, Tooltip, TooltipTrigger } from '@material-web/react'
export default function MultiLine() {
return (
<TooltipTrigger>
<IconButton aria-label="Grant value">
<Icon name="info" />
</IconButton>
<Tooltip>
Grant value is calculated using the closing stock price from the day before the grant date.
</Tooltip>
</TooltipTrigger>
)
}Rich tooltip
A rich tooltip gives more context about an element. Use it for longer text, such as a definition or an explanation.
Set variant="rich" for a tooltip with a subhead and supporting text. Write the subhead as a Heading, and the supporting text after it. A rich tooltip is up to 320dp wide, and is placed below its element, centered and 4dp away. Set placement to move it.
import { Icon, IconButton, Tooltip, TooltipTrigger } from '@material-web/react'
import { Heading } from 'react-aria-components'
export default function Rich() {
return (
<TooltipTrigger>
<IconButton aria-label="Favorite">
<Icon name="star" />
</IconButton>
<Tooltip variant="rich">
<Heading>Favorite</Heading>
Find this later in your favorites.
</Tooltip>
</TooltipTrigger>
)
}Use a Tooltip for a rich tooltip with no buttons or links. The keyboard cannot reach what is inside a Tooltip: for one with buttons or links, see Rich tooltips with actions.
Rich tooltips with actions
For a rich tooltip with buttons or links, put a TooltipPopover in a PreviewTrigger, after the element. Write the subhead as a Heading, then the supporting text, then the buttons as Buttons with variant="text". The buttons are placed side by side below the text: use up to two, with short labels.
Note: Put the supporting text in a Text when the tooltip has buttons or the text holds a link. Text written without one shares the buttons' row.
In a PreviewTrigger, the TooltipPopover opens 0.6s into a hover or keyboard focus, or on a long press on a touch screen. Set delay to change the 0.6s.
- The pointer can move onto the popover and stay over it.
- Tab from the element moves the focus into the popover, through its links and buttons from top to bottom, and then on to the element after the trigger.
- The popover closes 1.5s after the pointer has left both it and its element and the focus has gone.
- Escape closes it at once from its element, and after the close delay from inside the popover. Set a shorter
closeDelayto shorten both.
import { Button, Icon, IconButton, PreviewTrigger, TooltipPopover } from '@material-web/react'
import { Heading, Text } from 'react-aria-components'
export default function RichActions() {
return (
<>
<PreviewTrigger>
<IconButton aria-label="Add others">
<Icon name="person_add" />
</IconButton>
<TooltipPopover>
<Heading>Add others</Heading>
<Text>Share this collection with friends and family.</Text>
<Button variant="text">Learn more</Button>
<Button variant="text">Share</Button>
</TooltipPopover>
</PreviewTrigger>
<IconButton aria-label="Next">
<Icon name="arrow_forward" className="rtl:icon-mirrored" />
</IconButton>
</>
)
}Persistent rich tooltips
For a rich tooltip that opens on a press and not on a hover, put a TooltipPopover in a DialogTrigger, after the element. Avoid a persistent rich tooltip on an icon button.
Set isNonModal on the TooltipPopover and put a Dialog from react-aria-components in it. Name the dialog with a Heading with slot="title". The tooltip then behaves as follows:
- It stays open when the pointer leaves.
- It closes on a press of another element, which also receives the press.
- It closes on Escape, and the focus returns to its element.
- A
Buttonwithslot="close"inside it closes it too. - Tab stays inside it while it is open.
Without isNonModal, the popover is modal: the page behind it is hidden from assistive technology, the focus stays in the popover, and a press outside only closes it.
import { Button, TooltipPopover } from '@material-web/react'
import { Dialog, DialogTrigger, Heading, Text } from 'react-aria-components'
export default function Persistent() {
return (
<>
<DialogTrigger>
<Button variant="outlined">Image quality</Button>
<TooltipPopover isNonModal>
<Dialog>
<Heading slot="title">New settings available</Heading>
<Text>Now you can adjust the uploaded image quality.</Text>
<Button variant="text" slot="close">
Got it
</Button>
</Dialog>
</TooltipPopover>
</DialogTrigger>
<Button variant="text">Storage</Button>
</>
)
}To show a tooltip as the page loads, render a TooltipPopover with isOpen and a triggerRef, without a trigger. It is placed by the element of the ref, as with React Aria's custom anchor. Close it in onOpenChange, which is called on Escape and on a press of another element. A button inside it closes it in its onPress.
function NewSettings() {
const settings = useRef<HTMLButtonElement>(null)
const [isOpen, setOpen] = useState(true)
return (
<>
<IconButton ref={settings} aria-label="Settings">
<Icon name="settings" />
</IconButton>
<TooltipPopover triggerRef={settings} isOpen={isOpen} onOpenChange={setOpen} isNonModal>
<Dialog>
<Heading slot="title">New settings available</Heading>
<Text>Now you can adjust the uploaded image quality.</Text>
<Button variant="text" onPress={() => setOpen(false)}>
Got it
</Button>
</Dialog>
</TooltipPopover>
</>
)
}Labels and descriptions
A tooltip describes its element and does not name it. While the tooltip is open, the element refers to it with aria-describedby. An element with no visible text, such as an IconButton, still needs an aria-label, even when the tooltip shows the same text.
<TooltipTrigger>
<IconButton aria-label="Delete">
<Icon name="delete" />
</IconButton>
<Tooltip>Delete</Tooltip>
</TooltipTrigger>Triggers
A trigger decides what opens its tooltip:
| Trigger | Holds | Opens on |
|---|---|---|
TooltipTrigger | A Tooltip | A hover or keyboard focus |
PreviewTrigger | A TooltipPopover | A hover or keyboard focus, or a long press on a touch screen |
DialogTrigger | A TooltipPopover | A press |
Set trigger="focus" on a TooltipTrigger to open its tooltip on focus only.
import { Icon, IconButton, Tooltip, TooltipTrigger } from '@material-web/react'
export default function Triggers() {
return (
<>
<TooltipTrigger>
<IconButton aria-label="Undo">
<Icon name="undo" className="rtl:icon-mirrored" />
</IconButton>
<Tooltip>Undo, on hover or focus</Tooltip>
</TooltipTrigger>
<TooltipTrigger trigger="focus">
<IconButton aria-label="Redo">
<Icon name="redo" className="rtl:icon-mirrored" />
</IconButton>
<Tooltip>Redo, on focus alone</Tooltip>
</TooltipTrigger>
</>
)
}For a TooltipPopover in a PreviewTrigger, see Rich tooltips with actions. For one in a DialogTrigger, see Persistent rich tooltips.
Custom trigger element
The element of a TooltipTrigger can be a Button, an IconButton, a Fab or any other focusable React Aria component.
To describe another element, such as an element of your own or a third-party component, wrap it in React Aria's Focusable. The element must be able to take the focus, so give one that is not a native control a tabIndex and a role.
import { Button, Fab, Icon, Tooltip, TooltipTrigger } from '@material-web/react'
import { Focusable } from 'react-aria-components'
export default function Elements() {
return (
<>
<TooltipTrigger>
<Button variant="tonal">Publish</Button>
<Tooltip>Publish to everyone</Tooltip>
</TooltipTrigger>
<TooltipTrigger>
<Fab aria-label="Compose">
<Icon name="edit" />
</Fab>
<Tooltip>Compose</Tooltip>
</TooltipTrigger>
<TooltipTrigger>
<Focusable>
<span
role="img"
aria-label="Verified"
tabIndex={0}
className="focus-ring flex rounded-shape-full text-primary icon-24"
>
<Icon name="verified" />
</span>
</Focusable>
<Tooltip>This account is verified</Tooltip>
</TooltipTrigger>
</>
)
}Controlled
Control the open state with isOpen and onOpenChange on the TooltipTrigger, or set the initial state with defaultOpen. onOpenChange is called when the tooltip would open or close.
import { Button, Tooltip, TooltipTrigger } from '@material-web/react'
import { useState } from 'react'
export default function Controlled() {
const [isOpen, setOpen] = useState(false)
return (
<>
<TooltipTrigger isOpen={isOpen} onOpenChange={setOpen}>
<Button variant="outlined">Sync</Button>
<Tooltip>Sync your files now</Tooltip>
</TooltipTrigger>
<span className="text-body-md text-on-surface-variant">
The tooltip is {isOpen ? 'open' : 'closed'}
</span>
</>
)
}A PreviewTrigger and a DialogTrigger take the same three props.
Opening and closing
A tooltip closes 1.5s after the pointer leaves. Set closeDelay on the TooltipTrigger or the PreviewTrigger to change this. Both delays are in milliseconds.
In a TooltipTrigger:
- A hover opens the tooltip after 0.5s, and keyboard focus opens it at once. Set
delayto change the 0.5s. - The tooltip closes at once when the focus leaves, on Escape, and on a press of its element, which
shouldCloseOnPresscontrols. - The tooltip stays open while the pointer is on it.
- One tooltip shows at a time. Once one has opened, hovering another element opens its tooltip at once and closes the first.
Note: A touch opens no tooltip, and a disabled element has none. The pointer's first move in a page opens none either, if it lands on a trigger.
import { Icon, IconButton, Tooltip, TooltipTrigger } from '@material-web/react'
export default function Delay() {
return (
<>
<TooltipTrigger delay={0} closeDelay={0}>
<IconButton aria-label="Undo">
<Icon name="undo" className="rtl:icon-mirrored" />
</IconButton>
<Tooltip>Undo, at once</Tooltip>
</TooltipTrigger>
<TooltipTrigger delay={1000} closeDelay={3000}>
<IconButton aria-label="Redo">
<Icon name="redo" className="rtl:icon-mirrored" />
</IconButton>
<Tooltip>Redo, after a second</Tooltip>
</TooltipTrigger>
</>
)
}Disabled
A disabled element shows no tooltip: it cannot be focused and reports no hover.
To turn a tooltip off while its element stays enabled, set isDisabled on the TooltipTrigger.
import { Icon, IconButton, Tooltip, TooltipTrigger } from '@material-web/react'
export default function Disabled() {
return (
<>
<TooltipTrigger isDisabled>
<IconButton aria-label="Share">
<Icon name="share" />
</IconButton>
<Tooltip>Share</Tooltip>
</TooltipTrigger>
<TooltipTrigger>
<IconButton aria-label="Delete" isDisabled>
<Icon name="delete" />
</IconButton>
<Tooltip>Delete</Tooltip>
</TooltipTrigger>
</>
)
}Widths
A tooltip wraps text wider than its maximum width: 200dp for a plain tooltip, and 320dp for a rich one. To change it, set a max-w-* class on the Tooltip.
import { Icon, IconButton, Tooltip, TooltipTrigger } from '@material-web/react'
import { Heading } from 'react-aria-components'
export default function Width() {
return (
<>
<TooltipTrigger>
<IconButton aria-label="Grant value">
<Icon name="info" />
</IconButton>
<Tooltip className="max-w-80">
Grant value is calculated using the closing stock price from the day before the grant
date.
</Tooltip>
</TooltipTrigger>
<TooltipTrigger>
<IconButton aria-label="Favorite">
<Icon name="star" />
</IconButton>
<Tooltip variant="rich" className="max-w-50">
<Heading>Favorite</Heading>
Find this later in your favorites.
</Tooltip>
</TooltipTrigger>
</>
)
}Placement
A plain tooltip is placed above its element, centered and 4dp away. Set placement on the Tooltip to the side of the element the tooltip is on, one of React Aria's placements. A second word aligns the tooltip with an edge of the element, as in top start or bottom end.
The tooltip flips to the other side where the window has no room.
import { Icon, IconButton, Tooltip, TooltipTrigger } from '@material-web/react'
const placements = [
['top', 'arrow_upward'],
['bottom', 'arrow_downward'],
['left', 'arrow_back'],
['right', 'arrow_forward'],
] as const
export default function Placement() {
return (
<>
{placements.map(([placement, icon]) => (
<TooltipTrigger key={placement}>
<IconButton variant="tonal" aria-label={placement}>
<Icon name={icon} />
</IconButton>
<Tooltip placement={placement}>{placement}</Tooltip>
</TooltipTrigger>
))}
</>
)
}In an app bar, set placement="bottom" to place the tooltip below its element.
Photos
import { AppBar, Icon, IconButton, Tooltip, TooltipTrigger } from '@material-web/react'
import { Heading } from 'react-aria-components'
const actions = [
['Add to favorites', 'star'],
['Share', 'share'],
['Download', 'download'],
] as const
export default function InAppBar() {
return (
<div className="h-40 w-full">
<AppBar>
<Heading slot="headline" level={2}>
Photos
</Heading>
{actions.map(([label, icon]) => (
<TooltipTrigger key={label}>
<IconButton slot="trailing" aria-label={label}>
<Icon name={icon} />
</IconButton>
<Tooltip placement="bottom">{label}</Tooltip>
</TooltipTrigger>
))}
</AppBar>
</div>
)
}Distance from element
Set offset on the Tooltip to the distance from the element: 4dp by default. Use offset={8} for an element with no visual boundary, such as text.
import { Button, Tooltip, TooltipTrigger } from '@material-web/react'
export default function Offset() {
return (
<>
<TooltipTrigger>
<Button variant="outlined">Default</Button>
<Tooltip>4dp away</Tooltip>
</TooltipTrigger>
<TooltipTrigger>
<Button variant="text">Text</Button>
<Tooltip offset={8}>8dp away</Tooltip>
</TooltipTrigger>
<TooltipTrigger>
<Button variant="outlined">Farther</Button>
<Tooltip offset={16}>16dp away</Tooltip>
</TooltipTrigger>
</>
)
}crossOffsetmoves the tooltip along the side of the element it is on.containerPaddingis the distance the tooltip keeps from the window's edges: 8dp (the default).
Customization
Pass classes in className to restyle one tooltip. A class of yours replaces the tooltip's own class for the same property. See Styling for the classes, the states and the theme.
import { Icon, IconButton, Tooltip, TooltipTrigger } from '@material-web/react'
export default function Custom() {
return (
<>
<TooltipTrigger>
<IconButton aria-label="Delete">
<Icon name="delete" />
</IconButton>
<Tooltip className="bg-error text-on-error">Delete</Tooltip>
</TooltipTrigger>
<TooltipTrigger>
<IconButton aria-label="Share">
<Icon name="share" />
</IconButton>
<Tooltip className="rounded-shape-full px-space-150">Share</Tooltip>
</TooltipTrigger>
<TooltipTrigger>
<IconButton aria-label="Download">
<Icon name="download" />
</IconButton>
<Tooltip data-theme="dark" variant="rich">
Saved to your downloads folder.
</Tooltip>
</TooltipTrigger>
</>
)
}- Color: To use other color roles, pass a container color and the on-color of that container, as in
bg-error text-on-error. - Functions:
className,styleand the children can be functions of the tooltip's state. See Children as a function. - Ancestors: A tooltip is rendered at the end of the page, not inside the element it is written in. A class or a
data-themeon an element around its trigger does not reach it. Set it on theTooltipor theTooltipPopoveritself, or on the root element. - Every tooltip: To restyle all the tooltips at once, change the theme.
Use cases
Material lists what people should be able to do with assistive technology:
- Receive a tooltip message
- Activate a tooltip with a keyboard or switch input
Interaction and style
- Color contrast: Every text in a plain or a rich tooltip, the labels of its buttons included, has 4.5:1 contrast or more with its container, in light and dark schemes at every contrast level. Keep that contrast when you change its colors.
- Motion: With reduced motion, a tooltip opens and closes at once.
- Forced colors: A plain and a rich tooltip keep an edge in forced colors.
- Hover and focus: A hover opens a
Tooltipafter 0.5s, and keyboard focus opens it at once. It stays open while the pointer is on it, and closes 1.5s after the pointer leaves, or at once when the focus leaves. Material advises that a tooltip stay long enough to read without disrupting the task, and that it hide no crucial information. - Touch: A touch shows no tooltip, and a disabled element shows none. A
TooltipPopoverin aPreviewTriggeropens on a long press. For a rich tooltip that opens on a press, use a persistent rich tooltip.
Focus
- The keyboard cannot reach what is inside a
Tooltip. Use aTooltipPopoverfor a tooltip with buttons or links. - In a
PreviewTrigger, Tab from the element goes through the popover's links and buttons, and then on to the rest of the page. The focus moves from top to bottom and is not trapped, as Material advises. - In a
DialogTrigger, Tab stays in the dialog, and Escape closes it and returns the focus to its element.
Keyboard navigation
| Keys | Actions |
|---|---|
| Tab | Move the focus to the element, which opens its Tooltip, or the TooltipPopover of a PreviewTrigger |
| Space or Enter | Press the focused element, which closes its Tooltip, or opens a persistent rich tooltip |
| Escape | Close the tooltip |
- Escape, or the focus leaving, closes a
Tooltip. - In a
PreviewTrigger, Escape closes the popover at once from its element, and after the close delay from inside the popover.
Labeling elements
- A
Tooltiphas thetooltiprole, as Material advises. - A tooltip describes its element while it is open, and does not name it. An
IconButtonstill needs itsaria-label. See Labels and descriptions. - A
TooltipPopoverin aPreviewTriggerhas thedialogrole. Its element reports it witharia-haspopupandaria-expanded, and is described by it while it is open. - In a
DialogTrigger, name theDialogwith aHeadingwithslot="title". - Label each button and link in a
TooltipPopoveras its own page describes, such as buttons.
Tooltip
className, style and children can be functions of placement, isEntering, isExiting and state.
These defaults differ from the ones in the table: placement is top, or bottom for a rich tooltip, offset is 4 and containerPadding is 8.
variant'plain' | 'rich'Default'plain'Two variants: plain and rich
Plain tooltips briefly describe a UI element. They're best used for labelling UI elements with no text, like icon-only buttons and fields.
Rich tooltips provide additional context about a UI element.
Rich tooltips are best used for longer text like definitions or explanations.
Props of Tooltip (22)
classNameClassNameOrFunction<TooltipRenderProps>Default'react-aria-Tooltip'The CSS className for the element. A function may be provided to compute the class based on component state.
triggerRefRefObject<Element | null>The ref for the element which the tooltip positions itself with respect to.
When used within a TooltipTrigger this is set automatically. It is only required when used standalone.
isEnteringbooleanWhether the tooltip is currently performing an entry animation.
isExitingbooleanWhether the tooltip is currently performing an exit animation.
UNSTABLE_portalContainerdeprecatedElementDefaultdocument.bodyThe container element in which the overlay portal will be placed. This may have unknown behavior depending on where it is portalled to.
placement'start' | 'end' | 'bottom' | 'bottom left' | 'bottom right' | 'bottom start' | 'bottom end' | 'top' | 'top left' | 'top right' | 'top start' | 'top end' | 'left' | 'left top' | 'left bottom' | 'start top' | 'start bottom' | 'right' | 'right top' | 'right bottom' | 'end top' | 'end bottom'Default'top'The placement of the tooltip with respect to the trigger.
containerPaddingnumberDefault12The placement padding that should be applied between the element and its surrounding container.
offsetnumberDefault0The additional offset applied along the main axis between the element and its anchor element.
crossOffsetnumberDefault0The additional offset applied along the cross axis between the element and its anchor element.
shouldFlipbooleanDefaulttrueWhether the element should flip its orientation (e.g. top to bottom or left to right) when there is insufficient room for it to render completely.
isOpenbooleanWhether the element is rendered.
arrowBoundaryOffsetnumberDefault0The minimum distance the arrow's edge should be from the edge of the overlay element.
defaultOpenbooleanWhether the overlay is open by default (uncontrolled).
onOpenChange(isOpen: boolean) => voidHandler that is called when the overlay's open state changes.
aria-labelstringDefines a string value that labels the current element.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.
aria-describedbystringIdentifies the element (or elements) that describes the object.
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.
childrenChildrenOrFunction<T>The children of the component. A function may be provided to alter the children based on component state.
styleCSSProperties | (values: TooltipRenderProps & { defaultStyle: CSSProperties; }) => CSSProperties | undefinedThe inline style for the element. A function may be provided to compute the style based on component state.
renderDOMRenderFunction<'div', TooltipRenderProps>Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components.
Requirements:
- You must render the expected element type (e.g. if
<button>is expected, you cannot render an<a>). - Only a single root DOM element can be rendered (no fragments).
- You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate.
- You must render the expected element type (e.g. if
refRef<HTMLDivElement>
Tooltip also takes the 70 attributes and events of the element it renders.
TooltipTrigger
The default delay is 500 and the default closeDelay is 1500.
Props of TooltipTrigger (9)
childrenrequiredReactNodeisDisabledbooleanWhether the tooltip should be disabled, independent from the trigger.
delaynumberDefault1500The delay time for the tooltip to show up. See guidelines.
closeDelaynumberDefault500The delay time for the tooltip to close. See guidelines.
trigger'hover' | 'focus'Default'hover'By default, opens for both focus and hover. Can be made to open only for focus.
shouldCloseOnPressbooleanDefaulttrueWhether the tooltip should close when the trigger is pressed.
isOpenbooleanWhether the overlay is open by default (controlled).
defaultOpenbooleanWhether the overlay is open by default (uncontrolled).
onOpenChange(isOpen: boolean) => voidHandler that is called when the overlay's open state changes.
TooltipPopover
The default placement is bottom, the default offset is 4 and the default containerPadding is 8.
Props of TooltipPopover (37)
classNameClassNameOrFunction<PopoverRenderProps>Default'react-aria-Popover'The CSS className for the element. A function may be provided to compute the class based on component state.
triggerstringThe name of the component that triggered the popover. This is reflected on the element as the
data-triggerattribute, and can be used to provide specific styles for the popover depending on which element triggered it.triggerRefRefObject<Element | null>The ref for the element which the popover positions itself with respect to.
When used within a trigger component such as DialogTrigger, MenuTrigger, Select, etc., this is set automatically. It is only required when used standalone.
isEnteringbooleanWhether the popover is currently performing an entry animation.
isExitingbooleanWhether the popover is currently performing an exit animation.
shouldSkipAnimationbooleanWhether the popover should appear and disappear without an entry or exit animation. This is used by components such as PreviewTrigger to skip animations when quickly swapping between overlays.
UNSTABLE_portalContainerdeprecatedElementDefaultdocument.bodyThe container element in which the overlay portal will be placed. This may have unknown behavior depending on where it is portalled to.
offsetnumberDefault8The additional offset applied along the main axis between the element and its anchor element.
placement'start' | 'end' | 'bottom' | 'bottom left' | 'bottom right' | 'bottom start' | 'bottom end' | 'top' | 'top left' | 'top right' | 'top start' | 'top end' | 'left' | 'left top' | 'left bottom' | 'start top' | 'start bottom' | 'right' | 'right top' | 'right bottom' | 'end top' | 'end bottom'Default'bottom'The placement of the element with respect to its anchor element.
containerPaddingnumberDefault12The placement padding that should be applied between the element and its surrounding container.
crossOffsetnumberDefault0The additional offset applied along the cross axis between the element and its anchor element.
shouldFlipbooleanDefaulttrueWhether the element should flip its orientation (e.g. top to bottom or left to right) when there is insufficient room for it to render completely.
shouldCloseOnInteractOutside(element: Element) => booleanWhen user interacts with the argument element outside of the popover ref, return true if onClose should be called. This gives you a chance to filter out interaction with elements that should not dismiss the popover. By default, onClose will always be called on interaction outside the popover ref.
isKeyboardDismissDisabledbooleanDefaultfalseWhether pressing the escape key to close the popover should be disabled.
Most popovers should not use this option. When set to true, an alternative way to close the popover with a keyboard must be provided.
boundaryElementElementDefaultdocument.bodyElement that that serves as the positioning boundary.
arrowRefRefObject<Element | null>A ref for the popover arrow element.
scrollRefRefObject<Element | null>DefaultoverlayRefA ref for the scrollable region within the overlay.
shouldUpdatePositionbooleanDefaulttrueWhether the overlay should update its position automatically.
maxHeightnumberThe maxHeight specified for the overlay element. By default, it will take all space up to the current viewport height.
arrowBoundaryOffsetnumberDefault0The minimum distance the arrow's edge should be from the edge of the overlay element.
getTargetRect(target: Element) => DOMRect | null | undefinedDefaulttarget.getBoundingClientRect()Overrides the target element's bounding rectangle. Useful for positioning relative to a specific point such as the mouse cursor (e.g. context menus) or text selection.
onFocusWithin(e: FocusEvent) => voidHandler that is called when the target element or a descendant receives focus.
onBlurWithin(e: FocusEvent) => voidHandler that is called when the target element and all descendants lose focus.
onFocusWithinChange(isFocusWithin: boolean) => voidHandler that is called when the the focus within state changes.
isNonModalbooleanWhether the popover is non-modal, i.e. elements outside the popover may be interacted with by assistive technologies.
Most popovers should not use this option as it may negatively impact the screen reader experience. Only use with components such as combobox, which are designed to handle this situation carefully.
isOpenbooleanWhether the overlay is open by default (controlled).
defaultOpenbooleanWhether the overlay is open by default (uncontrolled).
onOpenChange(isOpen: boolean) => voidHandler that is called when the overlay's open state changes.
childrenChildrenOrFunction<T>The children of the component. A function may be provided to alter the children based on component state.
styleCSSProperties | (values: PopoverRenderProps & { defaultStyle: CSSProperties; }) => CSSProperties | undefinedThe inline style for the element. A function may be provided to compute the style based on component state.
renderDOMRenderFunction<'div', PopoverRenderProps>Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components.
Requirements:
- You must render the expected element type (e.g. if
<button>is expected, you cannot render an<a>). - Only a single root DOM element can be rendered (no fragments).
- You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate.
- You must render the expected element type (e.g. if
slotstring | nullA slot name for the component. Slots allow the component to receive props from a parent component. An explicit
nullvalue indicates that the local props completely override all props received from a parent.aria-labelstringDefines a string value that labels the current element.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.
aria-describedbystringIdentifies the element (or elements) that describes the object.
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.
refRef<HTMLElement>
TooltipPopover also takes the 70 attributes and events of the element it renders.
PreviewTrigger
The default closeDelay is 1500.
Props of PreviewTrigger (7)
childrenrequiredReactNodeThe trigger and Popover that make up the preview trigger.
delaynumberDefault600The delay time in milliseconds before the preview opens.
closeDelaynumberDefault200The delay time in milliseconds before the preview closes.
isOpenbooleanWhether the overlay is open by default (controlled).
defaultOpenbooleanWhether the overlay is open by default (uncontrolled).
onOpenChange(isOpen: boolean) => voidHandler that is called when the overlay's open state changes.
isDisabledbooleanWhether the tooltip should be disabled, independent from the trigger.