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 display issues of close button in contextual light and dark modes #41126

Merged
merged 4 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
15 changes: 9 additions & 6 deletions scss/_close.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
--#{$prefix}btn-close-focus-shadow: #{$btn-close-focus-shadow};
--#{$prefix}btn-close-focus-opacity: #{$btn-close-focus-opacity};
--#{$prefix}btn-close-disabled-opacity: #{$btn-close-disabled-opacity};
--#{$prefix}btn-close-white-filter: #{$btn-close-white-filter};
// scss-docs-end close-css-vars

box-sizing: content-box;
Expand All @@ -21,6 +20,7 @@
padding: $btn-close-padding-y $btn-close-padding-x;
color: var(--#{$prefix}btn-close-color);
background: transparent var(--#{$prefix}btn-close-bg) center / $btn-close-width auto no-repeat; // include transparent for button elements
filter: var(--#{$prefix}btn-close-filter);
border: 0; // for button elements
@include border-radius();
opacity: var(--#{$prefix}btn-close-opacity);
Expand All @@ -47,17 +47,20 @@
}

@mixin btn-close-white() {
filter: var(--#{$prefix}btn-close-white-filter);
--#{$prefix}btn-close-filter: #{$btn-close-filter-dark};
}

.btn-close-white {
@include btn-close-white();
}

:root,
[data-bs-theme="light"] {
--#{$prefix}btn-close-filter: #{$btn-close-filter};
}

@if $enable-dark-mode {
@include color-mode(dark) {
.btn-close {
@include btn-close-white();
}
@include color-mode(dark, true) {
@include btn-close-white();
}
}
6 changes: 6 additions & 0 deletions scss/_variables-dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,9 @@ $accordion-button-active-icon-dark: url("data:image/svg+xml,<svg xmlns='http://
$carousel-indicator-active-bg-dark: $carousel-dark-indicator-active-bg !default;
$carousel-caption-color-dark: $carousel-dark-caption-color !default;
$carousel-control-icon-filter-dark: $carousel-dark-control-icon-filter !default;

//
// Close button
//

$btn-close-filter-dark: $btn-close-white-filter !default;
3 changes: 2 additions & 1 deletion scss/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,8 @@ $btn-close-opacity: .5 !default;
$btn-close-hover-opacity: .75 !default;
$btn-close-focus-opacity: 1 !default;
$btn-close-disabled-opacity: .25 !default;
$btn-close-white-filter: invert(1) grayscale(100%) brightness(200%) !default;
$btn-close-filter: null !default;
$btn-close-white-filter: invert(1) grayscale(100%) brightness(200%) !default; // Deprecated in v5.3.4
// scss-docs-end close-variables


Expand Down
69 changes: 45 additions & 24 deletions site/content/docs/5.3/components/close-button.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,70 @@ group: components
toc: true
---

## Example

Provide an option to dismiss or close a component with `.btn-close`. Default styling is limited, but highly customizable. Modify the Sass variables to replace the default `background-image`. **Be sure to include text for screen readers**, as we've done with `aria-label`.
## Basic Close Button

{{< example >}}
<button type="button" class="btn-close" aria-label="Close"></button>
{{< /example >}}

## Disabled state

Disabled close buttons change their `opacity`. We've also applied `pointer-events: none` and `user-select: none` to preventing hover and active states from triggering.
## Dark Variant

{{< example >}}
<button type="button" class="btn-close" disabled aria-label="Close"></button>
<div class="bg-dark p-2">
<button type="button" class="btn-close btn-close-white" aria-label="Close"></button>
</div>
{{< /example >}}

## Dark variant
## Dark

{{< deprecated-in "5.3.0" >}}

{{< callout warning >}}
**Heads up!** As of v5.3.0, the `.btn-close-white` class is deprecated. Instead, use `data-bs-theme="dark"` to change the color mode of the close button.
{{< /callout >}}
{{< example >}}
<div data-bs-theme="dark" class="bg-body p-2">
<button type="button" class="btn-close" aria-label="Close"></button>
</div>
{{< /example >}}

Add `data-bs-theme="dark"` to the `.btn-close`, or to its parent element, to invert the close button. This uses the `filter` property to invert the `background-image` without overriding its value.
## Light

{{< example class="bg-dark" >}}
<div data-bs-theme="dark">
{{< example >}}
<div data-bs-theme="light" class="bg-body p-2">
<button type="button" class="btn-close" aria-label="Close"></button>
<button type="button" class="btn-close" disabled aria-label="Close"></button>
</div>
{{< /example >}}

## CSS
## Light in dark

### Variables
{{< example >}}
<div data-bs-theme="dark" class="bg-body p-2">
<div data-bs-theme="light" class="bg-body p-2">
<button type="button" class="btn-close" aria-label="Close"></button>
</div>
</div>
{{< /example >}}

{{< added-in "5.3.0" >}}
## Dark in light

As part of Bootstrap's evolving CSS variables approach, close button now uses local CSS variables on `.btn-close` for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.
{{< example >}}
<div data-bs-theme="light" class="bg-body p-2">
<div data-bs-theme="dark" class="bg-body p-2">
<button type="button" class="btn-close" aria-label="Close"></button>
</div>
</div>
{{< /example >}}

{{< scss-docs name="close-css-vars" file="scss/_close.scss" >}}
## Toast and Close Button issue

### Sass variables
Forcing `data-bs-theme="light"` didn't work in dark mode. Now, the cross button is always dark.

{{< scss-docs name="close-variables" file="scss/_variables.scss" >}}
{{< example >}}
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header bg-warning" data-bs-theme="light">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">Warning!</strong>
<small>11 mins ago</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
This is a warning message.
</div>
</div>
{{< /example >}}
Loading