Enable dark theme if user prefers dark color scheme - no javascript version #4761
+13
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We probably can enable dark mode now.
This version uses system settings with media queries and doesn't need javascript. It is enabled by the Bootstrap option
$color-mode-type: media-query
. Previous version #4653 used javascript to track system settings and changedata-bs-theme
attributes accordingly.The problem with this no-javascript approach is that
data-bs-theme
attributes are ignored. But we're already using them for inverting close buttons on dark banners. When in light mode, dark banners have their close buttons inverted because banners themselves have a dark theme attribute. Aside from not working with$color-mode-type: media-query
, this approach has another drawback: you can't invert buttons on light banners in dark mode. Once the entire webpage gets its dark mode attribute, you can't go back to light mode.The solution in this PR is:
$color-mode-type: media-query
that will take care of most of light/dark mode stylingdata-bs-theme
on bannersdata-bs-theme