A simple text popup tip.
button/text/operation
. It's often used instead of the html title
attribute.import React from 'react';
import { Tooltip } from 'antd';
const App: React.FC = () => (
<Tooltip title="prompt text">
<span>Tooltip will show on mouse enter.</span>
</Tooltip>
);
export default App;
import { Button, Divider, Segmented, Tooltip } from 'antd';
import React, { useMemo, useState } from 'react';
const text = <span>prompt text</span>;
const buttonWidth = 70;
const gap = 8;
const btnProps = {
style: {
width: buttonWidth,
},
};
const App: React.FC = () => {
const options = ['Show', 'Hide', 'Center'];
const [arrow, setArrow] = useState('Show');
const mergedArrow = useMemo(() => {
if (arrow === 'Hide') {
return false;
}
if (arrow === 'Show') {
return true;
}
return {
pointAtCenter: true,
};
}, [arrow]);
return (
<div className="demo">
<Segmented
value={arrow}
options={options}
onChange={(val: string) => {
setArrow(val);
}}
/>
<Divider orientation="center">Content</Divider>
<div style={{ marginLeft: buttonWidth, display: 'flex', flexWrap: 'nowrap', columnGap: gap }}>
<Tooltip placement="topLeft" title={text} arrow={mergedArrow}>
<Button {...btnProps}>TL</Button>
</Tooltip>
<Tooltip placement="top" title={text} arrow={mergedArrow}>
<Button {...btnProps}>Top</Button>
</Tooltip>
<Tooltip placement="topRight" title={text} arrow={mergedArrow}>
<Button {...btnProps}>TR</Button>
</Tooltip>
</div>
<div
style={{
width: buttonWidth,
float: 'left',
display: 'flex',
flexDirection: 'column',
rowGap: gap,
}}
>
<Tooltip placement="leftTop" title={text} arrow={mergedArrow}>
<Button>LT</Button>
</Tooltip>
<Tooltip placement="left" title={text} arrow={mergedArrow}>
<Button>Left</Button>
</Tooltip>
<Tooltip placement="leftBottom" title={text} arrow={mergedArrow}>
<Button>LB</Button>
</Tooltip>
</div>
<div
style={{
width: buttonWidth,
marginLeft: buttonWidth * 4 + 24,
display: 'flex',
flexDirection: 'column',
rowGap: gap,
}}
>
<Tooltip placement="rightTop" title={text} arrow={mergedArrow}>
<Button>RT</Button>
</Tooltip>
<Tooltip placement="right" title={text} arrow={mergedArrow}>
<Button>Right</Button>
</Tooltip>
<Tooltip placement="rightBottom" title={text} arrow={mergedArrow}>
<Button>RB</Button>
</Tooltip>
</div>
<div
style={{
marginLeft: buttonWidth,
clear: 'both',
display: 'flex',
flexWrap: 'nowrap',
columnGap: gap,
}}
>
<Tooltip placement="bottomLeft" title={text} arrow={mergedArrow}>
<Button {...btnProps}>BL</Button>
</Tooltip>
<Tooltip placement="bottom" title={text} arrow={mergedArrow}>
<Button {...btnProps}>Bottom</Button>
</Tooltip>
<Tooltip placement="bottomRight" title={text} arrow={mergedArrow}>
<Button {...btnProps}>BR</Button>
</Tooltip>
</div>
</div>
);
};
export default App;
import { Button, Divider, Space, Tooltip } from 'antd';
import React from 'react';
const colors = [
'pink',
'red',
'yellow',
'orange',
'cyan',
'green',
'blue',
'purple',
'geekblue',
'magenta',
'volcano',
'gold',
'lime',
];
const customColors = ['#f50', '#2db7f5', '#87d068', '#108ee9'];
const App: React.FC = () => (
<>
<Divider orientation="left">Presets</Divider>
<Space wrap>
{colors.map((color) => (
<Tooltip title="prompt text" color={color} key={color}>
<Button>{color}</Button>
</Tooltip>
))}
</Space>
<Divider orientation="left">Custom</Divider>
<Space wrap>
{customColors.map((color) => (
<Tooltip title="prompt text" color={color} key={color}>
<Button>{color}</Button>
</Tooltip>
))}
</Space>
</>
);
export default App;
import { Button, Tooltip } from 'antd';
import React from 'react';
const text = <span>prompt text</span>;
const buttonWidth = 70;
const App: React.FC = () => (
<div>
<div style={{ marginLeft: buttonWidth, whiteSpace: 'nowrap' }}>
<Tooltip placement="topLeft" title={text}>
<Button>TL</Button>
</Tooltip>
<Tooltip placement="top" title={text}>
<Button>Top</Button>
</Tooltip>
<Tooltip placement="topRight" title={text}>
<Button>TR</Button>
</Tooltip>
</div>
<div style={{ width: buttonWidth, float: 'left' }}>
<Tooltip placement="leftTop" title={text}>
<Button>LT</Button>
</Tooltip>
<Tooltip placement="left" title={text}>
<Button>Left</Button>
</Tooltip>
<Tooltip placement="leftBottom" title={text}>
<Button>LB</Button>
</Tooltip>
</div>
<div style={{ width: buttonWidth, marginLeft: buttonWidth * 4 + 24 }}>
<Tooltip placement="rightTop" title={text}>
<Button>RT</Button>
</Tooltip>
<Tooltip placement="right" title={text}>
<Button>Right</Button>
</Tooltip>
<Tooltip placement="rightBottom" title={text}>
<Button>RB</Button>
</Tooltip>
</div>
<div style={{ marginLeft: buttonWidth, clear: 'both', whiteSpace: 'nowrap' }}>
<Tooltip placement="bottomLeft" title={text}>
<Button>BL</Button>
</Tooltip>
<Tooltip placement="bottom" title={text}>
<Button>Bottom</Button>
</Tooltip>
<Tooltip placement="bottomRight" title={text}>
<Button>BR</Button>
</Tooltip>
</div>
</div>
);
export default App;
#components-tooltip-demo-placement .ant-btn {
margin-left: 0;
margin-right: 8px;
margin-bottom: 8px;
width: 70px;
text-align: center;
padding: 0;
}
#components-tooltip-demo-placement .ant-btn {
margin-left: 8px;
margin-right: 0;
}
import { Button, Tooltip } from 'antd';
import React from 'react';
const App: React.FC = () => {
React.useEffect(() => {
document.documentElement.scrollTop = document.documentElement.clientHeight;
document.documentElement.scrollLeft = document.documentElement.clientWidth;
}, []);
return (
<div>
<div
style={{
width: '300vw',
height: '300vh',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<Tooltip title="Thanks for using antd. Have a nice day!" open>
<Button>Scroll The Window</Button>
</Tooltip>
</div>
</div>
);
};
export default App;
Property | Description | Type | Default |
---|---|---|---|
title | The text shown in the tooltip | ReactNode | () => ReactNode | - |
The following APIs are shared by Tooltip, Popconfirm, Popover.
Property | Description | Type | Default | Version |
---|---|---|---|---|
align | This value will be merged into placement's config, please refer to the settings rc-tooltip | object | - | |
arrow | Change arrow's visible state and change whether the arrow is pointed at the center of target. | boolean | { pointAtCenter: boolean } | true | 5.2.0 |
autoAdjustOverflow | Whether to adjust popup placement automatically when popup is off screen | boolean | true | |
color | The background color | string | - | 4.3.0 |
defaultOpen | Whether the floating tooltip card is open by default | boolean | false | 4.23.0 |
destroyTooltipOnHide | Whether destroy tooltip when hidden | boolean | false | |
getPopupContainer | The DOM container of the tip, the default behavior is to create a div element in body | (triggerNode: HTMLElement) => HTMLElement | () => document.body | |
mouseEnterDelay | Delay in seconds, before tooltip is shown on mouse enter | number | 0.1 | |
mouseLeaveDelay | Delay in seconds, before tooltip is hidden on mouse leave | number | 0.1 | |
overlayClassName | Class name of the tooltip card | string | - | |
overlayStyle | Style of the tooltip card | object | - | |
overlayInnerStyle | Style of the tooltip inner content | object | - | |
placement | The position of the tooltip relative to the target, which can be one of top left right bottom topLeft topRight bottomLeft bottomRight leftTop leftBottom rightTop rightBottom | string | top | |
trigger | Tooltip trigger mode. Could be multiple by passing an array | hover | focus | click | contextMenu | Array<string> | hover | |
open | Whether the floating tooltip card is open or not. Use visible under 4.23.0 (why?) | boolean | false | 4.23.0 |
zIndex | Config z-index of Tooltip | number | - | |
onOpenChange | Callback executed when visibility of the tooltip card is changed | (open: boolean) => void | - | 4.23.0 |
Please ensure that the child node of Tooltip
accepts onMouseEnter
, onMouseLeave
, onFocus
, onClick
events.