Skip to content

Commit

Permalink
[Dark-mode] Fixes for mobile (#1917)
Browse files Browse the repository at this point in the history
  • Loading branch information
chalin committed Apr 6, 2024
1 parent 4e56448 commit 6018506
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
6 changes: 4 additions & 2 deletions assets/js/dark-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@
btnToActive.classList.add('active')
btnToActive.setAttribute('aria-pressed', 'true')
activeThemeIcon.setAttribute('href', svgOfActiveBtn)
const themeSwitcherLabel = `${themeSwitcherText.textContent} (${btnToActive.dataset.bsThemeValue})`
themeSwitcher.setAttribute('aria-label', themeSwitcherLabel)
if (themeSwitcherText) {
const themeSwitcherLabel = `${themeSwitcherText.textContent} (${btnToActive.dataset.bsThemeValue})`
themeSwitcher.setAttribute('aria-label', themeSwitcherLabel)
}

if (focus) {
themeSwitcher.focus()
Expand Down
23 changes: 14 additions & 9 deletions assets/scss/_nav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,20 @@
}
}

// Support for showLightDarkModeMenu:
.bi {
width: 1em;
height: 1em;
vertical-align: -.125em;
fill: currentcolor;
}
.td-navbar .dropdown-menu .active .bi {
display: block !important
.td-light-dark-menu {
.bi {
// Adapted from: https://github.com/twbs/bootstrap/blob/main/site/layouts/_default/examples.html
width: 1em;
height: 1em;
vertical-align: -.125em;
fill: currentcolor;
}

&.dropdown {
@include media-breakpoint-down(lg) {
position: unset;
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</li>
{{ end -}}
{{ if .Site.Params.ui.showLightDarkModeMenu -}}
<li class="nav-item dropdown">
<li class="td-light-dark-menu nav-item dropdown">
{{ partial "theme-toggler" . }}
</li>
{{ end -}}
Expand Down
4 changes: 3 additions & 1 deletion layouts/partials/theme-toggler.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
{{ if not $isExamples }}data-bs-display="static"{{ end }}
aria-label="Toggle theme (auto)">
<svg class="bi my-1 theme-icon-active"><use href="#circle-half"></use></svg>
<span class="{{ if $isExamples }}visually-hidden{{ else }}d-lg-none ms-2{{ end }}" id="bd-theme-text">Toggle theme</span>
{{- /* Disable menu name for Docsy:
<span class="{{ if $isExamples }}visually-hidden{{ else }}d-lg-none ms-2{{ end }}" id="bd-theme-text">Toggle theme</span>
*/}}
</button>
<ul class="dropdown-menu dropdown-menu-end{{ if $isExamples }} shadow{{ end }}" aria-labelledby="bd-theme-text">
<li>
Expand Down

0 comments on commit 6018506

Please sign in to comment.