Styling styled components acts unexpectedly
See original GitHub issueCurrent behavior:
Styling information is lost for consecutive styles. I suspect but cannot confirm that it’s a regression, because it appears that the code no longer works. Nevertheless, currently it doesn’t throw any errors besides not functioning as expected.
To reproduce:
import { css } from "@emotion/css";
import styled from "@emotion/styled";
export const ClearButton = styled('button')`
margin: 0;
padding: 0;
border: 0;
background: transparent;
font: inherit;
/* // Inherit font settings (doesn’t work in IE7-) */
/* // line-height: normal; // Override line-height to avoid spacing issues */
line-height: 0; /* // Due to Flexbox issues */
/* Remove mystery padding in Gecko browsers.
* See https://bugzilla.mozilla.org/show_bug.cgi?id=140562
*/
::-moz-focus-inner {
padding: 0;
border: 0;
}
cursor: pointer;
:focus {
outline: none;
}
`;
const newstyle = css`
:hover {
opacity: 0.7;
}
:focus {
opacity: 0.7;
outline: none;
}
`
// Result has no hover activity, however, no error is thrown either.
export const ClearButtonHover_Broken = styled(ClearButton)(newstyle)
export const ClearButtonHover_AlsoBroken = styled(ClearButton)`${newstyle}`
export const ClearButtonHover_Works = styled(ClearButton)`
:hover {
opacity: 0.7;
}
:focus {
opacity: 0.7;
outline: none;
}
`;
`
export const ClearButtonHover = styled(ClearButton)(newstyle)
Expected behavior:
Consistent styling or errors if this isn’t valid usage of the new API
Environment information:
react
version: 17.0.1@emotion/react
version: 11.1.5
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (6 by maintainers)
Top Results From Across the Web
styled-component stopped working after refactoring
Using the following, I was able to render the component and styles no problem: import React from "react"; import ReactDOM from "react-dom"; ...
Read more >Styled-Components in Action - Medium
Styled -Components is a new CSS tool, created by Max Stoiber and Glen Maddern, which helps you organize CSS in your React project....
Read more >React Render Props with Ts & styled-components | Part 2
We want a component that acts as an adapter between the GridLayout and what ... A second prop, style , will categorically contain...
Read more >Styling Components In React - Smashing Magazine
In this tutorial, we're going to learn how to style React components using four major styling strategies — with examples on how to...
Read more >How common is using styled components? : r/reactjs - Reddit
Is this where the style is css in the components code? ... hope nobody places a new div between two elements and breaks...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is Emotion meant to support inherence in the way
styled-components
does? I assumed it should, but this suggests otherwise: https://codesandbox.io/s/trusting-boyd-uvc6x?file=/src/App.jsEmotion-react v11.7.1 Emotion-styled v11.6.0
Fair enough, since there’s a solution inside this thread that should suffice for now. I also got a lot busier since making this issue.