emotion: Styling styled components acts unexpectedly
Current 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:
reactversion: 17.0.1@emotion/reactversion: 11.1.5
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (6 by maintainers)
Is Emotion meant to support inherence in the way
styled-componentsdoes? 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