File tree 2 files changed +43
-4
lines changed
packages/mui-system/src/createStyled
test/regressions/fixtures/componentSelector
2 files changed +43
-4
lines changed Original file line number Diff line number Diff line change @@ -152,10 +152,15 @@ export default function createStyled(input = {}) {
152
152
} ) ;
153
153
154
154
const transformStyle = ( style ) => {
155
- // On the server Emotion doesn't use React.forwardRef for creating components, so the created
156
- // component stays as a function. This condition makes sure that we do not interpolate functions
157
- // which are basically components used as a selectors.
158
- if ( typeof style === 'function' && style . __emotion_real !== style ) {
155
+ // - On the server Emotion doesn't use React.forwardRef for creating components, so the created
156
+ // component stays as a function. This condition makes sure that we do not interpolate functions
157
+ // which are basically components used as a selectors.
158
+ // - `style` could be a styled component from a babel plugin for component selectors, This condition
159
+ // makes sure that we do not interpolate them.
160
+ if ( style . __emotion_real === style ) {
161
+ return style ;
162
+ }
163
+ if ( typeof style === 'function' ) {
159
164
return function styleFunctionProcessor ( props ) {
160
165
return processStyle ( props , style ) ;
161
166
} ;
Original file line number Diff line number Diff line change
1
+ import * as React from 'react' ;
2
+ import { styled } from '@mui/material/styles' ;
3
+
4
+ const Child = styled ( 'div' , {
5
+ target : 'child' , // simulate a class name from @emotion /babel-plugin
6
+ } ) ( {
7
+ color : 'blue' ,
8
+ } ) ;
9
+
10
+ const Parent = styled ( 'div' ) `
11
+ ${ Child } {
12
+ color: red;
13
+ }
14
+ ` ;
15
+
16
+ const Parent2 = styled ( 'div' ) ( {
17
+ [ Child ] : {
18
+ color : 'red' ,
19
+ } ,
20
+ } ) ;
21
+
22
+ export default function ComponentSelector ( ) {
23
+ return (
24
+ < div >
25
+ < Child > I am blue.</ Child >
26
+ < Parent >
27
+ < Child > I am red (literal).</ Child >
28
+ </ Parent >
29
+ < Parent2 >
30
+ < Child > I am red (object).</ Child >
31
+ </ Parent2 >
32
+ </ div >
33
+ ) ;
34
+ }
You can’t perform that action at this time.
0 commit comments