Skip to content

Commit

Permalink
fix: set back align content for header navbar (#1331)
Browse files Browse the repository at this point in the history
* fix: set back align content for header navbar

* tests: regression test on navbar content alignement

* refactor: remove test file
  • Loading branch information
12rambau authored May 30, 2023
1 parent 5facdea commit 181edb6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
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

0 comments on commit 181edb6

Please sign in to comment.