Skip to content

Tab-item is modifying .html files #238

Closed

Description

@ramibd

Describe the bug

I'm making a sphinx web page to post work reports, mostly plotly HTML charts. I used .. raw:: html to add the graphs into my .rst file. Now, for better visualization purposes, I'm grouping my charts using sphinx-design tabs property.

Code:

.. tab-set::

   .. tab-item:: Level SA

      .. raw:: html

        <div style="text-align: center;">
        <iframe src="PATH\chart.html" style="border: none; width: 1005px; height: 450px"></iframe>
        </div> 

   .. tab-item:: MoM SA

      .. raw:: html

        <div style="text-align: center;">
        <iframe src="PATH\chart.html" style="border: none; width: 1005px; height: 450px"></iframe>
        </div> 

At first it worked, but then I started having issues with overlapping legends and problems on other features. This doesnt happen when i'm on the first layer of the tabs, only when i got to other layers. Also, if i refresh the web page while, for exemple, the second layer is selected, the error doesnt occur.

HTML on the first layer:

Image

HTML on the second layer:

Image

I tried swapping to sphinx-tabs, instead of sphinx-design, but the same happened. I also tried modifying the _static\tabs.css file, but couldn't figure out where the problem comes from. Does any one knows if there is a way to bypass this behavior?

Reproduce the bug

.Create a tab-set

.Add mutiple tab-item

.Use .. raw:: html to embed a html file in each tab-item

List your environment

No response

Activity

  1. added
    bug
    on May 8, 2025
  2. ramibd commented on May 12, 2025

    @ramibd
    Author

    I tested a bunch but couldnt make it work. Now i know that the problem is not the plot's height/width compared to it's parent container. I think it might be in the rendering of the html wile the tab isn't selected, because if i select a tab with error while the page is loading, the selected tab gets normalized and the normal ano presents the issue.

  3. chrisjsewell commented on Nov 10, 2026

    @chrisjsewell
    Member

    Thanks for the detailed report. This comes from how Plotly lays out, not from sphinx-design changing your HTML. Unselected tab panels are hidden with display: none, so a chart inside one is drawn at zero size. That is why it looks right when the page loads with that tab selected, and why sphinx-tabs behaves the same way. The usual fix is to make the chart re-layout when its tab becomes visible: use Plotly's config={'responsive': True}, and add a small script that dispatches a resize event to the chart when its tab's input changes. Embedding the plot div directly, instead of an iframe, also helps. Closing as answered, but feel free to follow up if that does not work for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions