compose shouldForwardProp#670
Conversation
|
I didn't totally understand this issue before but I get it now, below is how I think we could solve it. If this solves your issue, add this to the PR and I'll merge it. diff --git a/packages/create-emotion-styled/src/index.js b/packages/create-emotion-styled/src/index.js
index 4ac2ee9..cf6126d 100644
--- a/packages/create-emotion-styled/src/index.js
+++ b/packages/create-emotion-styled/src/index.js
@@ -25,11 +25,18 @@ function createEmotionStyled(emotion: Emotion, view: ReactType) {
let identifierName
let stableClassName
let shouldForwardProp
+ let customShouldForwardProp
if (options !== undefined) {
staticClassName = options.e
identifierName = options.label
stableClassName = options.target
- shouldForwardProp = options.shouldForwardProp
+ shouldForwardProp = customShouldForwardProp =
+ tag.__emotion_forwardProp && options.shouldForwardProp
+ ? propName =>
+ tag.__emotion_forwardProp(propName) &&
+ // $FlowFixMe
+ options.shouldForwardProp(propName)
+ : options.shouldForwardProp
}
const isReal = tag.__emotion_real === tag
const baseTag =
@@ -75,6 +82,7 @@ function createEmotionStyled(emotion: Emotion, view: ReactType) {
static __emotion_styles: Interpolations
static __emotion_base: Styled
static __emotion_target: string
+ static __emotion_forwardProp: void | (string => boolean)
static withComponent: (ElementType, options?: StyledOptions) => any
componentWillMount() {
@@ -148,6 +156,7 @@ function createEmotionStyled(emotion: Emotion, view: ReactType) {
Styled.__emotion_styles = styles
Styled.__emotion_base = baseTag
Styled.__emotion_real = Styled
+ Styled.__emotion_forwardProp = customShouldForwardProp
Object.defineProperty(Styled, 'toString', {
enumerable: false,
value() { |
|
Hello and thank you for the quick reply and suggested solution. I am currently testing it locally and will report back this week. Initial results look promising. 😄 |
Codecov Report
|
| identifierName = options.label | ||
| stableClassName = options.target | ||
| shouldForwardProp = options.shouldForwardProp | ||
| shouldForwardProp = customShouldForwardProp = |
There was a problem hiding this comment.
do we need to keep 2 variables for this?
|
Updated to remove extra This appears to be working well across all of the components and website in mineral-ui. Thanks again for your solution and responsiveness. |
|
LGTM, can't merge it though, so you'll have to w8 for @mitchellhamilton 😉 |
What:
Compose
shouldForwardPropon composedstyledcomponentsWhy:
I am investigating the migration of a library that is currently built on Glamorous, which may soon be deprecated.
When composing styled components, I have noticed that Emotion and Glamorous seem to work differently. Glamorous respects the inner component's filtered props, whereas Emotion does not appear to.
In Mineral, in our emotion branch, we are attempting to provide a wrapper around
styled, which adds a customshouldForwardPropthat enables filtering of props based on the HTML tag being rendered, a feature that also exists in Glamorous. This works fine until styled components are composed, at which point the outershouldForwardProptakes precedence and the inner one is completely ignored, thus the resulting component does not receive the expected props.I see that this issue was also discussed in
#659
Is this functionality desired, planned, achievable, or other?
How:
Implemented updates as suggested by @mitchellhamilton
Checklist: