Skip to content
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

Nesting of tabs and dropdowns etc #217

Open
BarrySmith opened this issue Aug 9, 2024 · 2 comments
Open

Nesting of tabs and dropdowns etc #217

BarrySmith opened this issue Aug 9, 2024 · 2 comments
Labels
enhancement New feature or request more info needed

Comments

@BarrySmith
Copy link

Context

Is it (would it be) possible to allow nesting of tabs, dropdowns etc?

I tried putting a dropdown inside a tab-item and get the error message:

WARNING: The parent of a 'tab-item' should be a 'tab-set' [design.tab]
/Users/barrysmith/Src/petsc/doc/objects.md:170: WARNING: All children of a 'tab-set' should be 'tab-item' [design.tab]

Proposal

Allowing nesting of tabs, dropdowns etc?

Tasks and updates

No response

@BarrySmith BarrySmith added the enhancement New feature or request label Aug 9, 2024
@chrisjsewell
Copy link
Member

Heya yeh should be possible, can you provide a "minimal working example" of the warning being raised

keitaay added a commit to keitaay/sandbox-sbt that referenced this issue Jan 14, 2025
@keitaay
Copy link

keitaay commented Jan 14, 2025

I know it's been a while since @BarrySmith first opened this thread, but here's an example. I'm using MyST Markdown instead of rST (not that it should matter for the end result), but this code...

::::::{dropdown} Manually created dropdown
This is some text before the tab-set.
:::::{tab-set}
::::{tab-item} Label for Tab 1
This is content for the 1st tab.
:::{dropdown} another dropdown for funsies
text
:::
::::
::::{tab-item} Label for Tab 2
This is content for the 2nd tab!
::::
:::::
::::::

...produces what I think is exactly what you're asking for:

image

So it's clearly possible to nest dropdowns and tabs in each other. You just need to make sure that you're nesting content inside a tab-item directive instead of its parent tab-set.

I do have a related question for you, though, @chrisjsewell. I seem to be able to do this correctly when I manually define nested dropdowns/tab set directives - but when I try to create a tab-set inside a dropdown using a custom directive, the text does not render correctly.

For example, I tried to create a similar dropdown to what I showed above - but using a locally-defined directive. Instead of getting tabs nested inside a dropdown (i.e. two dropdowns that look identical to each other), the contents of my auto-generated tab set just get rendered as plain text.

image

Here's a repo where I recreated this issue in an otherwise-bare-bones document; use this particular commit if necessary.

The only clue I have is these error messages:

DEBUG: Created tab 'Label for Tab 1' with content:
This is content for the 1st tab.
DEBUG: Created tab 'Label for Tab 2' with content:
This is content for the 2nd tab!
DEBUG: Created tab set with 2 tabs
DEBUG: Created dropdown: 'Automatically created dropdown'

[PATH REDACTED]/doc-test/source/index.md:19: WARNING: The parent of a 'tab-item' should be a 'tab-set' [design.tab] [design.tab]
[PATH REDACTED]/doc-test/source/index.md:19: WARNING: The parent of a 'tab-item' should be a 'tab-set' [design.tab] [design.tab]
[PATH REDACTED]/doc-test/source/index.md:22: WARNING: All children of a 'tab-set' should be 'tab-item' [design.tab] [design.tab]

I'm confused by this, though, since the contents of make_node_tabset are defined as string representations of my tab-item directives. And this seems to be the only way that I can build the doc to completion; if I keep self.content as a list of nodes, I get the following exception:

DEBUG: Created tab 'Label for Tab 2' with content:
This is content for the 2nd tab!
[PATH REDACTED]/doc-test/source/index.md:19: WARNING: The parent of a 'tab-item' should be a 'tab-set' [design.tab] [design.tab]
[PATH REDACTED]/doc-test/source/index.md:19: WARNING: The parent of a 'tab-item' should be a 'tab-set' [design.tab] [design.tab]

Traceback (most recent call last):
[parts of traceback omitted for brevity]
  File "[PATH REDACTED]/doc-test/source/_ext/enforcer.py", line 101, in run
    node = make_node_dropdown(self, name_arg)
  File "[PATH REDACTED]/doc-test/source/_ext/enforcer.py", line 68, in make_node_dropdown
    node_tabs = make_node_tabset(self, standard_want)
  File "[PATH REDACTED]/doc-test/source/_ext/enforcer.py", line 52, in make_node_tabset
    node = TabSetDirective.run_with_defaults(self)
  File "/opt/miniconda3/envs/[CONDA ENV NAME REDACTED]/lib/python3.13/site-packages/sphinx_design/tabs.py", line 37, in run_with_defaults
    self.state.nested_parse(self.content, self.content_offset, tab_set)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/[CONDA ENV NAME REDACTED]/lib/python3.13/site-packages/myst_parser/mocking.py", line 174, in nested_parse
    "\n".join(block),
    ~~~~~~~~~^^^^^^^
TypeError: sequence item 0: expected str instance, container found

Exception occurred:
  File "/opt/miniconda3/envs/[CONDA ENV NAME REDACTED]/lib/python3.13/site-packages/myst_parser/mocking.py", line 174, in nested_parse
    "\n".join(block),
    ~~~~~~~~~^^^^^^^
TypeError: sequence item 0: expected str instance, container found

This reads to me (a Sphinx noob) as a damned-if-you-do-damned-if-you-don't situation. Any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request more info needed
Projects
None yet
Development

No branches or pull requests

3 participants