[PROTO]: handle data-bs-theme differently #39295
Draft
+401
−15
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.
Description
This PR suggests to change the way we handle
data-bs-theme
by automatically settingcolor
andbackground-color
values with the following rule:It allows users to set
data-bs-theme
on any element and have the correct colors applied to it. For example:Based on that statement, it would mean that we could maybe remove some
color: var(--bs-{component}-color)
andbackground-color: var(--bs-{component}-bg)
rules from our components.In order to apply this rule within components,
color-mode
mixin is rewritten to either apply the@content
to:root, [data-bs-theme="light"]
or[data-bs-theme="{theme}"]
.This PR also shows how to fix an issue in our components; for instance where a light accordion is declared within a dark div, its icons have not the right color because we only had the following rule:
This issue can be seen in this CodePen
Because of the CSS cascade order, it seems not possible to specify the CSS var with a class because the priority between nested data themes can mess up everything. The idea is to declare those specific CSS variables at the root level:
This code could have been written in
_root.scss
since it's a global rule but if we do that for the accordions, when a custom CSS build will be made, the user will have extra useless CSS variables.In order to check everything, I've create a temporary (or not?) example page: https://deploy-preview-39295--twbs-bootstrap.netlify.app/docs/5.3/examples/dark-mode/
Type of changes
Checklist
npm run lint
)Live previews
Related issues
Closes Does not apply Body color in dark mode. When, adding the data-bs-theme="dark" attribute to the <div> element #39138
Potential for contrast issues with '.btn-close' class #39765 might be closed depending on the final content of this PR
Closes [Docs] Colour modes for individual elements #39915 (might be closed depending on the final content of this PR and the associated explanation)
Chrome/Edge default color-scheme scrollbars #40414 might be closed by this PR
TODO