File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -152,6 +152,37 @@ describe('#style', () => {
152152 fontFamily : 'title2' ,
153153 } ,
154154 } )
155+ // https://github.com/gregberge/xstyled/issues/288
156+ expect (
157+ JSON . stringify (
158+ fontFamily ( {
159+ fontFamily : {
160+ _ : { _ : 'title' , hover : 'title2' } ,
161+ md : { _ : 'title3' , hover : 'title4' } ,
162+ } ,
163+ theme,
164+ } ) ,
165+ null ,
166+ 2 ,
167+ ) ,
168+ ) . toEqual (
169+ JSON . stringify (
170+ {
171+ fontFamily : 'title' ,
172+ '&:hover' : {
173+ fontFamily : 'title2' ,
174+ } ,
175+ '@media (min-width: 400px)' : {
176+ fontFamily : 'title3' ,
177+ '&:hover' : {
178+ fontFamily : 'title4' ,
179+ } ,
180+ } ,
181+ } ,
182+ null ,
183+ 2 ,
184+ ) ,
185+ )
155186 } )
156187
157188 it ( 'works with breakpoints' , ( ) => {
Original file line number Diff line number Diff line change @@ -36,7 +36,20 @@ export const getVariants = <T extends Props>(props: T): PropsVariants<T> => {
3636 for ( const value in screens ) {
3737 medias [ value ] = mediaMinWidth ( getBreakpointMin ( screens , value ) )
3838 }
39- return { ...medias , ...states }
39+ const variants = { ...medias , ...states }
40+
41+ // Move at-rules to the end, since they don't increase specificity by
42+ // themselves but might need to override something that does.
43+ // See https://github.com/gregberge/xstyled/issues/288
44+ for ( const [ value , selector ] of Object . entries ( variants ) ) {
45+ if ( selector && selector . startsWith ( '@' ) ) {
46+ delete variants [ value ]
47+ // @ts -ignore
48+ variants [ value ] = selector
49+ }
50+ }
51+
52+ return variants
4053}
4154
4255export const getCachedVariants = < T extends Props > (
You can’t perform that action at this time.
0 commit comments