Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media queries don't work when using theming function #66

Open
aloker opened this issue Apr 28, 2018 · 9 comments
Open

Media queries don't work when using theming function #66

aloker opened this issue Apr 28, 2018 · 9 comments
Labels

Comments

@aloker
Copy link
Contributor

aloker commented Apr 28, 2018

When I provide a literal style object, media queries are considered.

const ResponsiveOk = styled("div")({
  color: "green",
  "@media screen and (min-width: 400px)": {
    color: "red"
  }
});

If I use a theme callback instead, media queries do not work anymore:

const ResponsiveNotOk = styled("div")(({ theme }) => ({
  color: "green",
  "@media screen and (min-width: 400px)": {
    color: "red"
  }
}));

Demo: https://codesandbox.io/s/m9v69xvo3x
Resize the output window above/below 400 pixel to see the difference: the top row switches between red and green, the bottom row doesn't.

Am I missing something conceptually here or is this supposed to work?

@kof
Copy link
Member

kof commented Apr 28, 2018

Looks like a bug

@lttb
Copy link
Member

lttb commented Apr 29, 2018

Hi! Thank you for the issue, it looks like a bug with @media and function rules in jss, described here: cssinjs/jss#706

@vbersch
Copy link

vbersch commented Jun 14, 2018

The same problem exists for '&:hover', '&:before' and '&:after'.
Those all do work in jss in combination with theming.

@MarcusNotheis
Copy link

MarcusNotheis commented Jun 14, 2018

Example snippet for @vbersch's issue:
this works:

const Link = styled('a')({
  color: '#24292e',
  '&:before': {
    content: '"*"'
  }
})

this doesn't:

const Link = styled('a')((props) => ({
  color: '#24292e',
  '&:before': {
    content: '"*"'
  }
}))

Both patterns are working fine in react-jss

@jmadson
Copy link

jmadson commented Jul 25, 2018

I love this JSS plugin! Unfortunately we're experiencing the same issue. Our team has been able to work around it by providing an object which contains functions when the props/theme are needed, but I feel it would be more efficient if we could provide a function which returns a single object instead.

For example (modifying the above for illustration purposes), this works:

const Link = styled('a')({
  color: ({ theme }) => theme.palette.primary.main
  textDecoration: "none",
  '&:hover': {
    textDecoration: "underline"
  }
})

But this does not:

const Link = styled('a')(({ theme }) => ({
  color: theme.palette.primary.main
  textDecoration: "none",
  '&:hover': {
    textDecoration: "underline"
  }
}))

@likethemammal
Copy link

Still experiencing the bug with '&:hover' as @MarcusNotheis described

@HenriBeck
Copy link
Member

HenriBeck commented May 6, 2019

We are currently working on porting this implementation to v10 of jss and also moving it into react-jss in cssinjs/jss#1094

@HenriBeck
Copy link
Member

There will be no more work done in this repo. I will add a test case for this bug for the new styled API to see if it's fixed there.

@likethemammal
Copy link

@HenriBeck Ah okay. Amazingly quick response, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants