[PROTO]: handle data-bs-theme differently#39295
[PROTO]: handle data-bs-theme differently#39295julien-deramond wants to merge 2 commits intomainfrom
Conversation
|
Note to revisit #39977 after I merge it for v5.3.4. |
|
Currently when building with :root,
[data-bs-theme] {
//...This injects the data tag, ignoring both May I suggest a localised mixin to remediate this? So the top of @mixin root_root() {
@if not $enable-dark-mode or $color-mode-type == "media-query" {
:root {
@content;
}
} @else {
:root,
[data-bs-theme="light"] {
@content;
}
}
}
@include root_root() {
color-scheme: light;
// Note: Custom variable values only support SassScript inside `#{}`.
//...Output stays the same for normal/default compile but makes for a cleaner CSS with (Can also be done in #41232 ?) [EDIT] Ummmm.. seems |
Description
This PR suggests to change the way we handle
data-bs-themeby automatically settingcolorandbackground-colorvalues with the following rule:It allows users to set
data-bs-themeon 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-modemixin is rewritten to either apply the@contentto: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.scsssince 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