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

fix: set back align content for header navbar #1331

Merged
merged 3 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<label class="sidebar-toggle primary-toggle" for="__primary">
<span class="fa-solid fa-bars"></span>
</label>
{% set navbar_start, navbar_class, navbar_align = navbar_align_class() %}
{% if theme_navbar_start %}
<div class="navbar-header-items__start">
<div class="{{ navbar_start }} navbar-header-items__start">
{% for navbar_item in theme_navbar_start %}
<div class="navbar-item">{% include navbar_item %}</div>
{% endfor %}
</div>
{% endif %}
{% set navbar_class, navbar_align = navbar_align_class() %}
<div class="{{ navbar_class }} navbar-header-items">
{% if theme_navbar_center %}
<div class="{{ navbar_align }} navbar-header-items__center">
Expand Down
6 changes: 3 additions & 3 deletions src/pydata_sphinx_theme/toctree.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ def navbar_align_class() -> List[str]:
"""Return the class that aligns the navbar based on config."""
align = context.get("theme_navbar_align", "content")
align_options = {
"content": ("col-lg-9", "me-auto"),
"left": ("", "me-auto"),
"right": ("", "ms-auto"),
"content": ("col-lg-3", "col-lg-9", "me-auto"),
"left": ("", "", "me-auto"),
"right": ("", "", "ms-auto"),
}
if align not in align_options:
raise ValueError(
Expand Down
34 changes: 18 additions & 16 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,25 +273,27 @@ def test_logo_template_rejected(sphinx_build_factory) -> None:
sphinx_build_factory("base", confoverrides=confoverrides).build()


def test_navbar_align_default(sphinx_build_factory) -> None:
"""The navbar items align with the proper part of the page."""
sphinx_build = sphinx_build_factory("base").build()
index_html = sphinx_build.html_tree("index.html")
assert "col-lg-9" in index_html.select(".navbar-header-items")[0].attrs["class"]


def test_navbar_align_right(sphinx_build_factory) -> None:
@pytest.mark.parametrize(
"align,klass",
[
("content", ("col-lg-3", "col-lg-9", "me-auto")),
("left", ("", "", "me-auto")),
("right", ("", "", "ms-auto")),
],
)
def test_navbar_align(align, klass, sphinx_build_factory) -> None:
"""The navbar items align with the proper part of the page."""
confoverrides = {"html_theme_options.navbar_align": "right"}
confoverrides = {"html_theme_options.navbar_align": align}
sphinx_build = sphinx_build_factory("base", confoverrides=confoverrides).build()

# Both the column alignment and the margin should be changed
index_html = sphinx_build.html_tree("index.html")
assert "col-lg-9" not in index_html.select(".navbar-header-items")[0].attrs["class"]
assert (
"ms-auto"
in index_html.select("div.navbar-header-items__center")[0].attrs["class"]
)
if klass[0]:
header_start = index_html.select(".navbar-header-items__start")[0]
assert klass[0] in header_start.attrs["class"]
if klass[1]:
header_items = index_html.select(".navbar-header-items")[0]
assert klass[1] in header_items.attrs["class"]
header_center = index_html.select(".navbar-header-items__center")[0]
assert klass[2] in header_center.attrs["class"]


def test_navbar_no_in_page_headers(sphinx_build_factory, file_regression) -> None:
Expand Down