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

Spinner: Enforce no background. #49695

Merged
merged 5 commits into from
Apr 15, 2023
Merged

Conversation

jasmussen
Copy link
Contributor

What?

In some environments, or when you have certain plugins active, the Spinner component can inherit a legacy background color from other spinners that share the components-spinner class name. In those cases, they might look like this:

before

... when they should look like this:

after

This PR adds an explicit "no background" rule, that should at lest prevent the CSS bleed.

Here's an example of CSS that might get inherited:

Screenshot 2023-04-10 at 18 58 49

Testing Instructions

If you're able to test in a Calypso environment, you should see no gray background behind the spinner.

@jasmussen jasmussen added [Type] Enhancement A suggestion for improvement. [Feature] UI Components Impacts or related to the UI component system labels Apr 10, 2023
@jasmussen jasmussen requested a review from ajitbohra as a code owner April 10, 2023 17:07
@jasmussen jasmussen self-assigned this Apr 10, 2023
@@ -26,6 +26,8 @@ export const StyledSpinner = styled.svg`
position: relative;
color: ${ COLORS.ui.theme };
overflow: visible;
opacity: 1;
background-color: none;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none is not a valid value for background-color. We can use transparent instead

@ciampo ciampo force-pushed the try/spinner-enforce-no-background branch from 7a8f167 to 0ae2761 Compare April 15, 2023 06:19
Copy link
Contributor

@ciampo ciampo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is good to go 🚀

  • Rebased on top of latest trunk
  • Swapped none for transparent for the background color reset
  • Updated snapshots
  • Added missing CHANGELOG entry

A final note: the changes in this PR can only be a temporary fix. The real fix is to avoid style overrides (even more so those using internal class names like components-spinner).

@ciampo ciampo enabled auto-merge (squash) April 15, 2023 06:25
@ciampo ciampo merged commit 9fd9dad into trunk Apr 15, 2023
@ciampo ciampo deleted the try/spinner-enforce-no-background branch April 15, 2023 06:51
@github-actions github-actions bot added this to the Gutenberg 15.7 milestone Apr 15, 2023
@jasmussen
Copy link
Contributor Author

Wow, thanks for bringing this home! 🙏

@@ -26,6 +26,8 @@ export const StyledSpinner = styled.svg`
position: relative;
color: ${ COLORS.ui.theme };
overflow: visible;
opacity: 1;
background-color: transparent;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also have been:

opacity: inherit;
background-color: inherit;

which effectively resets the styles that were set by a CSS class rule, and makes them to be inherited from a parent element. Just like if the child element never specified any background-color.

inherit is better in a sense that it doesn't express any opinion about what the background color should be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would inherit the background of its parent element.

If the structure is simply div.components-spinner > svg, then inherit would most likely make it transparent indeed, or at least the same background color as its parent.

But I like transparent in this case, as it is an easily readable statement: this component should always have a transparent background.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the structure is simply div.components-spinner > svg

In the spinner case however the structure is svg.components-spinner, both the class name and the Emotion-generated style are on the same element. It would work.

But never mind, I just wanted to share a possible alternative solution. And in case of background-color, transparent in the end means the same thing as inherit, just on a different conceptual level: "inherit the color of the layer that's under this one"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you're right, my mistake. But it would still inherit the background of its parent, might have its own background set. It would be invisible unless it was a tiling image, which would be unlikely, but nevertheless, not quite as explicit as "transparent".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you're right, too, about the tiling images etc. background-color is not inherited by default, as that would copy the style from the parent, and we don't want to do that. It would break gradients, tiles etc. The right default for background-color is transparent.

It's initial that is the real alternative solution that works:

opacity: initial;
background-color: initial;

jeherve added a commit to Automattic/jetpack that referenced this pull request May 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] UI Components Impacts or related to the UI component system [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants