Skip to content

Commit 811349b

Browse files
committed
Fixing dropdown unique id
1 parent 9b49ecd commit 811349b

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

src/sphinx_book_theme/_components.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
The remaining values in the user configuration are passed as kwargs to the func.
99
"""
1010
from sphinx.util import logging
11+
import hashlib
1112

1213
SPHINX_LOGGER = logging.getLogger(__name__)
1314

@@ -63,12 +64,14 @@ def component_dropdown(app, context, content="", items=[]):
6364
"""
6465
dropdown_items.append(link)
6566
dropdown_items = "\n".join(dropdown_items)
67+
dropdown_id = "menu-dropdown-"
68+
dropdown_id += hashlib.md5(dropdown_items.encode("utf-8")).hexdigest()[:5]
6669
html = f"""
6770
<div class="dropdown">
68-
<button class="btn dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
71+
<button class="btn dropdown-toggle" type="button" id="{dropdown_id}" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
6972
{content}
7073
</button>
71-
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
74+
<div class="dropdown-menu" aria-labelledby="{dropdown_id}">
7275
{dropdown_items}
7376
</div>
7477
</div>

src/sphinx_book_theme/assets/styles/sections/_header-primary.scss

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,20 @@ $header-default-height-narrow: 3rem;
7272
}
7373
}
7474

75+
.header__brand {
76+
padding: 0 1.5rem;
77+
}
78+
7579
// Ensure the header items don't touch the screen edge
7680
.header__start {
7781
padding-left: 1rem;
7882
}
7983

8084
@media (max-width: $breakpoint-md) {
81-
// Only apply on narrow screens since we want it centered on sidebar on wide
8285
.header__brand,
86+
.header__start,
8387
.header__end {
84-
padding-left: 1rem;
85-
padding-right: 0;
88+
padding-left: 0.5rem;
8689
}
8790
}
8891

0 commit comments

Comments
 (0)