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 theme toggle JavaScript and A11y #1628

Merged
merged 2 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions docs/assets/js/color-modes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/

(() => {
'use strict'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linting is not happy with this removal. I can reintroduce it if needed or we should change the rules. As you wish.

Copy link
Member

@XhmikosR XhmikosR Mar 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's needed here because the JS docs files here are treated as CJS and not modules.


const storedTheme = localStorage.getItem('theme')

const getPreferredTheme = () => {
Expand All @@ -29,12 +27,12 @@

const showActiveTheme = (theme, focus = false) => {
const themeSwitcher = document.querySelector('#bd-theme')
const themeSwitcherText = document.querySelector('#bd-theme-text')

if (!themeSwitcher || !themeSwitcherText) {
if (!themeSwitcher) {
return
}

const themeSwitcherText = document.querySelector('#bd-theme-text')
const activeThemeIcon = document.querySelector('.theme-icon-active use')
const btnToActive = document.querySelector(`[data-bs-theme-value="${theme}"]`)
const svgOfActiveBtn = btnToActive.querySelector('svg use').getAttribute('href')
Expand Down
4 changes: 4 additions & 0 deletions docs/assets/scss/_navbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@
}
}
}

.dropdown-menu-end {
--bs-dropdown-min-width: 8rem;
}
}

@include color-mode(dark) {
Expand Down
5 changes: 2 additions & 3 deletions docs/assets/scss/docs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@

.highlight {
margin-bottom: 0;
color: var(--bs-gray-200);
background-color: var(--bs-gray-800);
background-color: var(--bs-tertiary-bg);
border-radius: .5rem;

pre {
Expand All @@ -153,7 +152,7 @@

.btn-clipboard {
top: .5em;
background-color: var(--bs-gray-800);
background-color: var(--bs-tertiary-bg);
}

.btn {
Expand Down
13 changes: 7 additions & 6 deletions docs/layouts/partials/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,28 @@ <h5 class="offcanvas-title text-white" id="bdNavbarOffcanvasLabel">Bootstrap</h5
type="button"
aria-expanded="false"
data-bs-toggle="dropdown"
data-bs-display="static">
data-bs-display="static"
aria-label="Toggle theme (auto)">
<svg class="bi my-1 theme-icon-active"><use href="#circle-half"></use></svg>
<span class="d-lg-none ms-2">Toggle theme</span>
<span class="d-lg-none ms-2" id="bd-theme-text">Toggle theme</span>
</button>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="bd-theme" style="--bs-dropdown-min-width: 8rem;">
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="bd-theme-text">
<li>
<button type="button" class="dropdown-item d-flex align-items-center" data-bs-theme-value="light">
<button type="button" class="dropdown-item d-flex align-items-center" data-bs-theme-value="light" aria-pressed="false">
<svg class="bi me-2 opacity-50 theme-icon"><use href="#sun-fill"></use></svg>
Light
<svg class="bi ms-auto d-none"><use href="#check2"></use></svg>
</button>
</li>
<li>
<button type="button" class="dropdown-item d-flex align-items-center" data-bs-theme-value="dark">
<button type="button" class="dropdown-item d-flex align-items-center" data-bs-theme-value="dark" aria-pressed="false">
<svg class="bi me-2 opacity-50 theme-icon"><use href="#moon-stars-fill"></use></svg>
Dark
<svg class="bi ms-auto d-none"><use href="#check2"></use></svg>
</button>
</li>
<li>
<button type="button" class="dropdown-item d-flex align-items-center active" data-bs-theme-value="auto">
<button type="button" class="dropdown-item d-flex align-items-center active" data-bs-theme-value="auto" aria-pressed="true">
<svg class="bi me-2 opacity-50 theme-icon"><use href="#circle-half"></use></svg>
Auto
<svg class="bi ms-auto d-none"><use href="#check2"></use></svg>
Expand Down