mui-x icon indicating copy to clipboard operation
mui-x copied to clipboard

[charts] The tooltip should get a position option

Open alexfauquette opened this issue 2 years ago • 3 comments

Summary 💡

Come from this message: https://stackoverflow.com/questions/77590276/customize-the-tooltip-on-a-mui-graph

The solution: https://codesandbox.io/p/sandbox/reverent-night-xfjytg

The idea as I understand it is to force the x/y position of the popper instead of following the mouse position.

https://github.com/mui/mui-x/assets/45398769/f939b911-bb28-4a79-8893-d597b84c2eaf

Could be something like sltoProps.popper.placement = 'top' to force the tooltip to appear on top of the chart

Examples 🌈

No response

Motivation 🔦

No response

Search keywords: charts tooltip placement

alexfauquette avatar Dec 21 '23 17:12 alexfauquette

Maybe somewhat overlapping issue: image

If chart is placed near the edge of the screen, tooltip can be unreadable as it always gets placed to the right.

MonstraG avatar Mar 04 '24 11:03 MonstraG

I've discovered that popper's position options can already be passed:

<BarChart
	series={series}
	xAxis={[xAxis]}
	slotProps={{
		popper: {
			placement: "auto-start" // actually works
		}
	}}
	tooltip={{
		slotProps: {
			popper: {
				placement: "auto-start" // ignored
			}
		}
	}}
/>

but note how there are 2 ways to do it, and one of them doesn't do anything. My issue is resolved.

MonstraG avatar Mar 04 '24 12:03 MonstraG

@alexfauquette we should probably either remove tooltip.slotProps.popper from the typing (if not already) or do the merge correctly Classic slot merging stuff :laughing:

flaviendelangle avatar Mar 04 '24 12:03 flaviendelangle