-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[charts] Chart tooltips not working correctly in shadow dom #12452
Comments
I poked the bug a little more and asserted that it is indeed an issue with the container prop not being inherited from the MuiPopper defaultProps in the theme. |
Hey @mbond-SCW, Whilst testing your live example I came across another thing. When rendering the Chart in the normal DOM the styles get loaded when hovering the bars and then they also work for the shadow DOM: Screen.Recording.2024-03-15.at.11.09.58.mov |
Are there any news on this bug or suggestions for a workaround? I'm running into the same issue. What I noticed: MuiChartsTooltip: {
defaultProps: {
slotProps: {
popper: {
disablePortal: false, // in out theme, this defaults to true for the MuiPopper component
container: () => {
const shadowHost = document.querySelector('create-car-app');
const shadowRoot = shadowHost?.shadowRoot;
const createCarMain = shadowRoot?.querySelector('#createCarRoot');
return createCarMain || null;
},
},
},
},
}, But when I do it in my component, like so, it does not work (although I'd expect these two approaches to give the same result): <LineChart
xAxis={[{ data: [1, 2, 3, 5, 8, 10] }]}
series={[
{
data: [2, 5.5, 2, 8.5, 1.5, 5],
},
]}
width={500}
height={300}
tooltip={{
slotProps: {
popper: {
disablePortal: false,
container: () => {
const shadowHost = document.querySelector('create-car-app');
const shadowRoot = shadowHost?.shadowRoot;
const createCarMain =
shadowRoot?.querySelector('#createCarRoot');
return createCarMain || null;
},
},
},
}}
/> So it seems like when using the component, EDIT (2 hours later ^^): I made it work using the following code: const chartContainer = React.useRef<HTMLDivElement | null>(null);
return <div id={'chartContainer'} ref={chartContainer}>
<LineChart
xAxis={[{ data: [1, 2, 3, 5, 8, 10] }]}
series={[
{
data: [2, 5.5, 2, 8.5, 1.5, 5],
},
]}
width={500}
height={300}
slotProps={{
popper: {
disablePortal: false,
container: chartContainer.current,
},
}}
/>
</div> Key changes: the |
@AnnikaNissen Thanks for the clear explaination of your issue. Effectively. mui-x/packages/x-charts/src/LineChart/useLineChartProps.ts Lines 168 to 172 in 5b48909
You can overcome this issue with @mAllenBond This explain the root cause of your issue I never understood. In v6, |
This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue. Note @mAllenBond How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey. |
Steps to reproduce
Link to live example: Sandbox
The above example is forked from This sandbox which is from https://mui.com/material-ui/customization/shadow-dom/#how-to-use-the-shadow-dom-with-material-ui
Steps:
Current behavior
When embedding charts in our host env, we observed that tooltip styles and behavior are not properly contained in the shadow dom. My only guess would be that the popper component being used in the charts needs to have its container properly set, but I'm not sure how or if that's possible currently.
Expected behavior
The tooltip (popper) in mui charts should render properly in a shadow dom container.
Context
I am trying to accomplish precisely what is described above and demonstrated in the sandbox:
Your environment
npx @mui/envinfo
Tested on Google Chrome
Search keywords: charts tooltip shadow dom
Order ID: We use the Premium plan, I'm a dev and don't have the order ID or support key ^
The text was updated successfully, but these errors were encountered: