style(sidebar): swap expand chevrons for +/− indicators on nav sections

Streamlit's default sidebar section header uses a Material Symbols
expand_more chevron — three different icons (chevron down, chevron up,
sometimes a plain triangle) depending on version, all of which felt
inconsistent with the rest of the chrome.

Hide the built-in icon (svg / material-symbols span — covered with
multiple selectors for cross-version durability) and render our own
glyph as a right-aligned pseudo-element on the section-header button,
keyed off the standard ARIA aria-expanded attribute:
- collapsed → "+"
- expanded  → "−" (U+2212, visually balanced with +)

Hover deepens the indicator color to match the surrounding nav-link
hover treatment.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-02 17:23:49 +00:00
parent 904356f4e8
commit 209b5fb1aa

View File

@@ -335,6 +335,55 @@ body, .stApp {
box-shadow: none !important;
}
/* ---------- Section header expand indicator ----------
Swap Streamlit's default ``expand_more`` chevron in each sidebar
section header for a soft ``+`` / ```` pair. ``+`` when collapsed,
```` (U+2212, visually balanced with +) when expanded.
We hide any built-in icon Streamlit injects (svg or Material
Symbols span — exact element differs by Streamlit version) and
render our own glyph as a right-aligned pseudo-element keyed off
``aria-expanded``. The button itself gets a touch of right padding
so the label doesn't run into the indicator. */
[data-testid="stSidebarNavSectionHeader"] {
position: relative !important;
}
[data-testid="stSidebarNavSectionHeader"] button {
width: 100% !important;
padding-right: 22px !important;
background: transparent !important;
border: none !important;
}
[data-testid="stSidebarNavSectionHeader"] button svg,
[data-testid="stSidebarNavSectionHeader"] button [data-testid="stIconMaterial"],
[data-testid="stSidebarNavSectionHeader"] button span.material-symbols-rounded,
[data-testid="stSidebarNavSectionHeader"] button span.material-symbols-outlined,
[data-testid="stSidebarNavSectionHeader"] button span.material-icons,
[data-testid="stSidebarNavSectionHeader"] button span.material-icons-outlined {
display: none !important;
}
[data-testid="stSidebarNavSectionHeader"] button[aria-expanded]::after {
position: absolute;
right: 8px;
top: 50%;
transform: translateY(-50%);
font-size: 16px;
font-weight: 400;
line-height: 1;
color: var(--ink-tertiary);
transition: color 0.15s ease;
pointer-events: none;
}
[data-testid="stSidebarNavSectionHeader"] button[aria-expanded="false"]::after {
content: "+";
}
[data-testid="stSidebarNavSectionHeader"] button[aria-expanded="true"]::after {
content: "\2212";
}
[data-testid="stSidebarNavSectionHeader"] button:hover::after {
color: var(--ink) !important;
}
/* Inline + block code → mono with subtle accent chip. theme.py owns
the family + size; this layer adds the warm-fill background. */
[data-testid="stMarkdownContainer"] code {