Skip to content

Commit dd4f761

Browse files
authored
Make sticky_contents default to True (#371)
* Make sticky_contents default to True The sticky right-hand table of contents with scroll spy was introduced in 0.17.0 and has proven to be the preferred experience. This change enables it by default for all projects using the theme. Users can opt out by setting sticky_contents: false in html_theme_options. * Address Copilot review feedback - test: assert back-to-top and data-autoexpand absent when sticky disabled - docs: note contents_autoexpand only affects sticky TOC - changelog: clarify opt-out for both Python conf.py and YAML _config.yml
1 parent 7f3a96d commit dd4f761

4 files changed

Lines changed: 41 additions & 27 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Changed
11+
- **`sticky_contents` now defaults to `True`** — the sticky right-hand table of contents with scroll spy is now enabled by default for all projects using the theme. To revert to the classic TOC, set `sticky_contents: False` in `html_theme_options` in `conf.py`, or `sticky_contents: false` in YAML-based configuration (e.g. `_config.yml`).
12+
813
## [0.18.0] - 2026-02-24
914

1015
### Changed

docs/user/configuration.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,25 @@ filter to the site logo.
149149

150150
## Sticky Table of Contents
151151

152-
Enable a fixed right-hand table of contents with scroll spy and auto-expansion:
152+
The theme includes a fixed right-hand table of contents with scroll spy and
153+
auto-expansion, enabled by default.
154+
155+
### Features
156+
157+
- **Fixed positioning** — the TOC stays visible while scrolling
158+
- **Active section highlighting** — the current section is highlighted
159+
- **Copy section link** — hover over a TOC entry to reveal a copy icon
160+
- **Back to top button** — appears after scrolling down 300px
161+
- **Auto-expand subsections** — subsections expand as you scroll
162+
163+
### Disable sticky TOC
164+
165+
To revert to the classic (non-sticky) table of contents:
153166

154167
```python
155168
html_theme_options = {
156169
...
157-
"sticky_contents": True,
170+
"sticky_contents": False,
158171
...
159172
}
160173
```
@@ -165,30 +178,20 @@ For Jupyter Book projects:
165178
sphinx:
166179
config:
167180
html_theme_options:
168-
sticky_contents: true
181+
sticky_contents: false
169182
```
170183
171-
### Features
172-
173-
When enabled:
174-
- **Fixed positioning** — the TOC stays visible while scrolling
175-
- **Active section highlighting** — the current section is highlighted
176-
- **Copy section link** — hover over a TOC entry to reveal a copy icon
177-
- **Back to top button** — appears after scrolling down 300px
178-
- **Auto-expand subsections** — subsections expand as you scroll
179-
180184
### Disable auto-expansion
181185
182186
```python
183187
html_theme_options = {
184188
...
185-
"sticky_contents": True,
186189
"contents_autoexpand": False,
187190
...
188191
}
189192
```
190193

191-
When `contents_autoexpand` is `False`, only top-level section names are displayed.
194+
When `contents_autoexpand` is `False`, only top-level section names are displayed. Note that this option only has an effect when the sticky TOC is enabled (the default); it has no impact when `sticky_contents` is set to `False`.
192195

193196
## Customizing Toggle Buttons
194197

src/quantecon_book_theme/theme/quantecon_book_theme/theme.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ path_to_docs =
3131
persistent_sidebar = False
3232
plugins_list = []
3333
quantecon_project = True
34-
sticky_contents = False
34+
sticky_contents = True
3535
repository_branch =
3636
repository_url =
3737
single_page = False

tests/test_build.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -428,30 +428,36 @@ def test_sticky_toc(sphinx_build):
428428
"""Test that sticky_contents and contents_autoexpand options work correctly."""
429429
sphinx_build.copy()
430430

431-
# Test default behavior - sticky TOC should be disabled
431+
# Test default behavior - sticky TOC should be enabled by default
432432
sphinx_build.build()
433433
index_html = sphinx_build.get("index.html")
434434
toc_inner = index_html.find("div", class_="inner")
435-
# By default, sticky class should NOT be present
436-
assert toc_inner is None or "sticky" not in toc_inner.get("class", [])
435+
# By default, sticky class should be present
436+
assert toc_inner is not None
437+
assert "sticky" in toc_inner.get("class", [])
438+
# Default contents_autoexpand should be True
439+
assert toc_inner.get("data-autoexpand") == "true"
440+
# Back to top button should be present
441+
back_to_top = index_html.find("a", class_="back-to-top-btn")
442+
assert back_to_top is not None
437443
sphinx_build.clean()
438444

439-
# Test with sticky_contents enabled
445+
# Test with sticky_contents explicitly disabled
440446
cmd = [
441447
"-D",
442-
"html_theme_options.sticky_contents=True",
448+
"html_theme_options.sticky_contents=False",
443449
]
444450
sphinx_build.build(cmd)
445451
index_html = sphinx_build.get("index.html")
446452
toc_inner = index_html.find("div", class_="inner")
447-
# When enabled, sticky class should be present
448-
assert toc_inner is not None
449-
assert "sticky" in toc_inner.get("class", [])
450-
# Default contents_autoexpand should be True
451-
assert toc_inner.get("data-autoexpand") == "true"
452-
# Back to top button should be present
453+
# When disabled, sticky class should NOT be present
454+
assert toc_inner is None or "sticky" not in toc_inner.get("class", [])
455+
# Back to top button should NOT be present when sticky contents are disabled
453456
back_to_top = index_html.find("a", class_="back-to-top-btn")
454-
assert back_to_top is not None
457+
assert back_to_top is None
458+
# data-autoexpand attribute should NOT be present when sticky contents are disabled
459+
if toc_inner is not None:
460+
assert toc_inner.get("data-autoexpand") is None
455461
sphinx_build.clean()
456462

457463
# Test with sticky_contents enabled and contents_autoexpand disabled

0 commit comments

Comments
 (0)