Skip to content

Commit eda8049

Browse files
committed
make it work for nav level 0
1 parent 7b43a8d commit eda8049

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

src/pydata_sphinx_theme/assets/styles/sections/_sidebar-primary.scss

+18-20
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@
140140
.list-caption {
141141
list-style: none;
142142
padding-left: 0px;
143+
144+
.nav {
145+
display: block;
146+
}
143147
}
144148
li {
145149
position: relative;
@@ -150,21 +154,25 @@
150154
padding-right: 30px;
151155
}
152156

153-
details {
157+
> details {
154158
// Get rid of the default toggle icon
155159
> summary {
156160
display: flex;
157161
justify-content: space-between;
162+
align-items: baseline;
158163
list-style: none;
159164
&::-webkit-details-marker {
160165
display: none;
161166
}
162167
}
163168

164-
// The section is open, rotate the toggle icon (chevron) so it points down instead of to the right
169+
// The section is open/expanded, rotate the toggle icon (chevron) so it
170+
// points down instead of to the right
165171
&[open] {
166-
.fa-chevron-down {
167-
transform: rotate(180deg);
172+
> summary {
173+
.fa-chevron-down {
174+
transform: rotate(180deg);
175+
}
168176
}
169177
}
170178
}
@@ -173,9 +181,6 @@
173181
}
174182
// Navigation item chevrons
175183
span.toctree-toggle {
176-
height: 30px;
177-
width: 30px;
178-
179184
cursor: pointer;
180185

181186
display: inline-flex;
@@ -186,26 +191,19 @@
186191
background: var(--pst-color-surface);
187192
}
188193

189-
i {
194+
svg {
190195
display: inline-block;
191196
font-size: 0.75rem;
192197
text-align: center;
193198
&:hover {
194199
color: var(--pst-color-primary);
195200
}
196201
}
197-
}
198-
.label-parts {
199-
width: 100%;
200-
height: 100%;
201-
&:hover {
202-
background: none;
203-
}
204-
i {
205-
width: 30px;
206-
position: absolute;
207-
top: 0.3em; // aligning chevron with text
208-
right: 0em; // aligning chevron to the right
202+
203+
.toctree-l10 & {
204+
svg {
205+
font-size: inherit;
206+
}
209207
}
210208
}
211209
}

src/pydata_sphinx_theme/toctree.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,7 @@ def add_collapse_checkboxes(soup: BeautifulSoup) -> None:
364364
parentli.find("details")["open"] = None
365365

366366
# Nothing more to do, unless this has "children"
367-
subtree = element.find("ul")
368-
if not subtree:
367+
if not element.find("ul"):
369368
continue
370369

371370
# Add a class to indicate that this has children.
@@ -374,23 +373,26 @@ def add_collapse_checkboxes(soup: BeautifulSoup) -> None:
374373
if soup.new_tag is None:
375374
continue
376375

377-
# Modify the tree so that it looks like
376+
# Modify the tree so that it looks like:
378377
#
379378
# li.has-children
380379
# > details
381380
# > summary
382381
# > a.reference ~ span.toctree-toggle
383382
# > ul
384383

385-
# Create <details> and move everything under this TOC <li> entry inside it
384+
# Create <details> and move everything at this level into it
386385
details = soup.new_tag("details")
387386
details.extend(element.contents)
388387
element.append(details)
389388

390-
# Create <summary> and move the TOC <a> entry into it
389+
# Create <summary> and move the level's heading into it
391390
summary = soup.new_tag("summary")
392-
summary.append(details.a)
393391
details.insert(0, summary)
392+
summary.append(
393+
# heading
394+
element.select_one("details > p.caption, details > a.reference")
395+
)
394396

395397
# Create chevron icon and append to <summary>
396398
span = soup.new_tag(
@@ -401,9 +403,6 @@ def add_collapse_checkboxes(soup: BeautifulSoup) -> None:
401403
},
402404
)
403405
span.append(soup.new_tag("i", attrs={"class": "fa-solid fa-chevron-down"}))
404-
if "toctree-l0" in classes:
405-
# making label cover the whole caption text with css
406-
span["class"] = "label-parts"
407406
summary.append(span)
408407

409408
# If this has a "current" class, be expanded by default

0 commit comments

Comments
 (0)