React Tooltip - Getting Started
Tooltip is a UI component that allows you to display information over a specific element in your application.
This tutorial guides you through the following steps:
- Add a Tooltip to a page and configure core component settings.
- Customize Tooltip appearance.
The following live example demonstrates the result:
Each section in this tutorial describes a single configuration step. You can find the complete source code in the following GitHub repository:
Create and Configure Tooltip
Add DevExtreme to your React application and use the code below to create a Tooltip. To display the component, specify a target and define the showEvent or visible property.
- import 'devextreme/dist/css/dx.fluent.blue.light.css';
- import { Tooltip } from 'devextreme-react/tooltip';
- function App(): JSX.Element {
- return (
- <Tooltip
- target="#target"
- showEvent="mouseenter"
- />
- );
- }
This example creates three Button components and assigns Tooltips to them. Button ID attributes are specified as Tooltip targets. Additionally, this example configures the hideEvent property for all Tooltips:
- import 'devextreme/dist/css/dx.fluent.blue.light.css';
- import { Button } from 'devextreme-react/button';
- import { Tooltip } from 'devextreme-react/tooltip';
- function App(): JSX.Element {
- return (
- <div className="dx-viewport">
- <div className="buttons">
- <Button
- id="like"
- icon="like"
- />
- <Button
- id="trash"
- icon="trash"
- />
- <Button
- id="info"
- icon="info"
- />
- </div>
- <div className="tooltips">
- <Tooltip
- target="#like"
- showEvent="mouseenter"
- hideEvent="mouseleave"
- />
- <Tooltip
- target="#trash"
- showEvent="mouseenter"
- hideEvent="mouseleave"
- />
- <Tooltip
- target="#info"
- showEvent="mouseenter"
- hideEvent="mouseleave"
- />
- </div>
- </div>
- );
- }
Customize Tooltip
To customize Tooltip content, specify contentRender or contentComponent:
- function likeRender(): JSX.Element {
- return <div>Like</div>;
- }
- function trashRender(): JSX.Element {
- return (
- <div className='red-tooltip'>Delete</div>
- );
- }
- function infoRender(): JSX.Element {
- return (
- <div className='blue-tooltip'>Info</div>
- );
- }
- function App(): JSX.Element {
- return (
- <div className="tooltips">
- <Tooltip
- contentRender={likeRender}
- />
- <Tooltip
- contentRender={trashRender}
- />
- <Tooltip
- contentRender={infoRender}
- />
- </div>
- )
- }
You can use CSS to customize the Tooltip's appearance. The code snippets above assigned CSS classes to all tooltips. This example defines those styles (.red-tooltip and .blue-tooltip):
- .dx-overlay-wrapper > .dx-overlay-content:has(.blue-tooltip),
- .dx-overlay-wrapper > .dx-overlay-content:has(.blue-tooltip) .dx-popover-arrow::after {
- background-color: #0f6cbd;
- color: white;
- }
- .dx-overlay-wrapper > .dx-overlay-content:has(.red-tooltip),
- .dx-overlay-wrapper > .dx-overlay-content:has(.red-tooltip) .dx-popover-arrow::after {
- background-color: #d13438;
- color: white;
- }