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 are overwritten #2466

Closed
ontech7 opened this issue Dec 17, 2023 · 1 comment
Closed

Media queries are overwritten #2466

ontech7 opened this issue Dec 17, 2023 · 1 comment

Comments

@ontech7
Copy link

ontech7 commented Dec 17, 2023

I don't know if I should consider this as bug or not.

I used sx prop in the past with Material UI (based on emotion lib as well), and created nested components.

If I write:

import { Box } from "theme-ui";

export const CompA = ({ children, ssx }: Props) => {
  return (
    <Box 
      sx={{ 
        "@media (max-width: 768px)": { my: 1 }, 
        ...ssx
      }}
    >
      {children}
    </Box>
  )
}
import CompA from "./compA";

export const CompB = (props: Props) => {
  return (
    <CompA 
      ssx={{ 
        "@media (max-width: 768px)": { display: "flex" }
      }}
    >
      test
    </Box>
  )
}

The result, at runtime, will be only "@media (max-width: 768px)": { display: "flex" }, instead of combining them (in cascade) such as: "@media (max-width: 768px)": { mt: 1, display: "flex" }.

So, in order to achieve the "combination of the two", I need to redeclare mt: 1 prop, losing the sense of it.

I think it should be added, for declared media queries, a check like key.startsWith("@media") and check if the keys are equal. If so, you should add the prop inside the media query.
N.B.: In case it's the same property, it would be overwritten, and that's totally correct.

@ontech7
Copy link
Author

ontech7 commented Dec 17, 2023

/c

@ontech7 ontech7 closed this as completed Dec 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant