Skip to content

Update CustomContentOfTooltip example so that the tooltip does not jump around #328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/docs/exampleComponents/Tooltip/CustomContentOfTooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ const getIntroOfPage = (label) => {
};

const CustomTooltip = ({ active, payload, label }) => {
if (active && payload && payload.length) {
return (
<div className="custom-tooltip">
<p className="label">{`${label} : ${payload[0].value}`}</p>
<p className="intro">{getIntroOfPage(label)}</p>
<p className="desc">Anything you want can be displayed here.</p>
</div>
);
}

return null;
const isVisible = active && payload && payload.length;
return (
<div className="custom-tooltip" style={{ visibility: isVisible ? 'visible' : 'hidden' }}>
Copy link
Preview

Copilot AI Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider adding pointerEvents: isVisible ? 'auto' : 'none' to this style so the hidden tooltip container doesn't intercept mouse events and block interactions with underlying elements.

Suggested change
<div className="custom-tooltip" style={{ visibility: isVisible ? 'visible' : 'hidden' }}>
<div className="custom-tooltip" style={{ visibility: isVisible ? 'visible' : 'hidden', pointerEvents: isVisible ? 'auto' : 'none' }}>

Copilot uses AI. Check for mistakes.

{isVisible && (
<>
<p className="label">{`${label} : ${payload[0].value}`}</p>
<p className="intro">{getIntroOfPage(label)}</p>
<p className="desc">Anything you want can be displayed here.</p></>
)}
</div>
);
};

export default class Example extends PureComponent {
Expand All @@ -102,7 +102,7 @@ export default class Example extends PureComponent {
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="name" />
<YAxis />
<Tooltip content={<CustomTooltip />} />
<Tooltip content={CustomTooltip} />
<Legend />
<Bar dataKey="pv" barSize={20} fill="#8884d8" />
</BarChart>
Expand Down
Loading