Skip to content

Commit 0ddc394

Browse files
Carreaugabalafou
andcommitted
Do not generate dropdown in sidebar.
This should fix pydata#1735, it is complementary to pydata#1564 but with a different approach. Instead of generating the same navbar as the fullpage width one, it generate one with no dropdowns, with this, any css that tries to make downtown looks like normal links in html becomes unnecessary. Co-authored-by: gabalafou <[email protected]>
1 parent 5a7fef9 commit 0ddc394

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/pydata_sphinx_theme/theme/pydata_sphinx_theme/sections/sidebar-primary.html

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
{% if theme_navbar_center %}
77
<div class="sidebar-header-items__center">
88
{% for navbar_item in theme_navbar_center %}
9-
<div class="navbar-item">{% include navbar_item %}</div>
9+
{#
10+
In the mobile sidebar we do not want a dropdown, so set a large cutoff (999).
11+
#}
12+
{% with theme_header_links_before_dropdown=999 %}
13+
<div class="navbar-item">{% include navbar_item %}</div>
14+
{% endwith %}
1015
{% endfor %}
1116
</div>
1217
{% endif %}

src/pydata_sphinx_theme/toctree.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from functools import cache
44
from itertools import count
5-
from typing import Iterator, List, Union
5+
from typing import Iterator, List, Tuple, Union
66
from urllib.parse import urlparse
77

88
import sphinx
@@ -101,8 +101,18 @@ def unique_html_id(base_id: str):
101101
return next(get_or_create_id_generator(base_id))
102102

103103
@cache
104-
def generate_header_nav_before_dropdown(n_links_before_dropdown):
105-
"""The cacheable part."""
104+
def generate_header_nav_before_dropdown(
105+
n_links_before_dropdown,
106+
) -> Tuple[str, List[str]]:
107+
"""Return html for navbar and dropdown.
108+
109+
Given the number of links before the dropdown, return the html for the navbar,
110+
as well as the list of links to put in a dropdown.
111+
112+
Returns:
113+
- HTML str for the navbar
114+
- list of HTML str for the dropdown
115+
"""
106116
try:
107117
n_links_before_dropdown = int(n_links_before_dropdown)
108118
except Exception:

0 commit comments

Comments
 (0)