Skip to content

Scope the theme's close button rules to the theme's own close button - #7796

Open
nlemoine wants to merge 1 commit into
EasyCorp:5.xfrom
nlemoine:fix-btn-close-hover-background
Open

Scope the theme's close button rules to the theme's own close button#7796
nlemoine wants to merge 1 commit into
EasyCorp:5.xfrom
nlemoine:fix-btn-close-hover-background

Conversation

@nlemoine

Copy link
Copy Markdown
Contributor

Two bugs, same cause, so I put them in one PR.

Alert renders its dismiss button through Button, so it comes out as btn btn-invisible btn-close. The theme has five rules written for that button, in buttons.css and alerts.css. All five are selected on .btn-close alone. So they also hit plain Bootstrap close buttons: modal headers, toasts, offcanvas. Those don't have the --button-* custom properties (only the .btn rule declares them), and they don't have the .btn layout that some of these rules exist to undo.

Blank on hover, buttons.css:

.btn-close:not(:disabled):not(.disabled):hover {
    background: var(--button-hover-bg, var(--button-bg));
}

Both properties are missing on a plain close button. The declaration is then invalid at computed-value time, background falls back to its initial longhands, and background-image: none wipes the glyph. Bootstrap draws that glyph as a data-URI background, so the button is just empty on hover.

Black glyph in dark mode, alerts.css:

[data-bs-theme="dark"] .btn-close { filter: none }

Fine for our own button, its glyph is a child <svg> in currentColor, inverting it would be wrong. On a plain one it cancels --bs-btn-close-filter, and that filter is what turns Bootstrap's black glyph white. Black glyph on a dark background.

Repro: drop <button type="button" class="btn-close" data-bs-dismiss="modal"></button> into a modal header on any EasyAdmin page. Hover it, glyph gone. Switch to dark, glyph black.

The fix scopes the five rules to .btn.btn-close, so plain close buttons are left to Bootstrap. I also switched the two background declarations to background-color. My guess is the color was the intent anyway, the transition-property right above says background-color. The shorthand would keep wiping the glyph even where the variables resolve, it just doesn't show there.

Assets rebuilt with make build-assets. Compiled diff in public/app.*.css is those five rules and nothing else.

Alert renders its dismiss button through Button, so it comes out as
`btn btn-invisible btn-close`. The theme has five rules written for that
button, in buttons.css and alerts.css, and all five are selected on
`.btn-close` alone. So they also hit plain Bootstrap close buttons: modal
headers, toasts, offcanvas. Those don't have the `--button-*` custom
properties, only the `.btn` rule declares them, and they don't have the
`.btn` layout that some of these rules exist to undo.

Two of the five broke such a button.

`.btn-close:hover` painted `background: var(--button-hover-bg,
var(--button-bg))`. Both properties are missing there, so the declaration
was invalid at computed-value time, `background` fell back to its initial
longhands, and `background-image: none` wiped the glyph. Bootstrap draws
that glyph as a data-URI background, so the button went empty on hover.

`[data-bs-theme="dark"] .btn-close` reset `filter` to none. Fine for our
own button, its glyph is a child <svg> in currentColor and inverting it
would be wrong. On a plain one it cancelled `--bs-btn-close-filter`, and
that filter is what turns Bootstrap's black glyph white. Black glyph on a
dark surface.

Scoping the five rules to `.btn.btn-close` leaves plain close buttons to
Bootstrap. The two `background` declarations also become
`background-color`. My guess is the color was the intent anyway, the
transition-property right above says background-color.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant