Skip to content

Commit 1f7ba2c

Browse files
authored
Update CustomContentOfTooltip example so that the tooltip does not jump around (#328)
1 parent 09cb246 commit 1f7ba2c

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/docs/exampleComponents/Tooltip/CustomContentOfTooltip.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@ const getIntroOfPage = (label) => {
6969
};
7070

7171
const CustomTooltip = ({ active, payload, label }) => {
72-
if (active && payload && payload.length) {
73-
return (
74-
<div className="custom-tooltip">
75-
<p className="label">{`${label} : ${payload[0].value}`}</p>
76-
<p className="intro">{getIntroOfPage(label)}</p>
77-
<p className="desc">Anything you want can be displayed here.</p>
78-
</div>
79-
);
80-
}
81-
82-
return null;
72+
const isVisible = active && payload && payload.length;
73+
return (
74+
<div className="custom-tooltip" style={{ visibility: isVisible ? 'visible' : 'hidden' }}>
75+
{isVisible && (
76+
<>
77+
<p className="label">{`${label} : ${payload[0].value}`}</p>
78+
<p className="intro">{getIntroOfPage(label)}</p>
79+
<p className="desc">Anything you want can be displayed here.</p></>
80+
)}
81+
</div>
82+
);
8383
};
8484

8585
export default class Example extends PureComponent {
@@ -102,7 +102,7 @@ export default class Example extends PureComponent {
102102
<CartesianGrid strokeDasharray="3 3" />
103103
<XAxis dataKey="name" />
104104
<YAxis />
105-
<Tooltip content={<CustomTooltip />} />
105+
<Tooltip content={CustomTooltip} />
106106
<Legend />
107107
<Bar dataKey="pv" barSize={20} fill="#8884d8" />
108108
</BarChart>

0 commit comments

Comments
 (0)