-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[Grid] Container responsive queries #25189
Comments
Hah, I came here to report this exact issue and see its here already. Its a bit strange that the grid is not responsive to its container, and instead computes based on viewport. This are many cases where one wants to render a component (which is using grid internally) within a smaller container / box etc etc. In such cases, not having the grid resize according to its own container leads to terrible UI. |
Interesting issue. There are, more or less two solutions track.
|
Came here to report the same issue, and I was also interested in a potential solution! I was looking for a way to pass a ref to my desired container component, as a prop or something similar. The javascript solution mentioned also seems to make sense. I am using FlexLayout in my react app, and would like to be able to have the Grid respond to each tab https://github.com/caplin/FlexLayout |
Given that Container Queries are now in Chrome Canary, and the immense utility and push for this that has been over the years I'd say this possibly (probably) would get other vendors in motion too. I actually came here looking for a way to decouple the breakpoints from the @media css implementation by allowing function values and thus having the freedom to let the breakpoint mean just about anything (but emulating container queries would clearly be the most common use case). Correct me if I'm wrong but this is not possible today, right? @oliviertassinari |
@membla looking at the syntax of the container query, it seems something that we could easily support. The main challenge is about the browser support. At which point should we consider the feature with enough adoption to expose an API for it? |
Yes, that's the question. But at least I think the scene is firmly set for it now. So should be something to be taken into consideration in future planning I reckon, I guess it also depends on what kind of integration/interoperability with the current @media query system you'd aim for. Anyway, my particular use case at the moment for something like this was very niche, I wanted to support |
Given slow adoption rates, I would imagine it would be a long time before Container Queries can be relied on, or? @oliviertassinari your demo (https://codesandbox.io/s/material-demo-forked-c5zpk?file=/demo.js:494-767) looks absolutely perfect. Doesnt that already solve the issue? I will try to implement the same and report back. |
Sorry now I'm a bit confused. The Box API (https://material-ui.com/components/box/) does not have the props you mentioned. |
@zehawki The docs of v4 !== the docs of v5. |
Hi @oliviertassinari is there an update to this in v5, now that's it formally out. ie is there a better way to do responsive grid? |
for people who want an alternative while waiting react-container-query
|
Intent to support container queries in chrome |
Container queries are available in Chromium as well as Safari. No impl. in Firefox but looks like they're working on it! https://caniuse.com/css-container-queries |
Container queries are also available for Tailwind |
@Mistes974 I had a quick play with the API, to see a bit how it feels like right now: import * as React from "react";
import { styled } from "@mui/system";
const Container = styled("div")({
display: "flex",
flexWrap: "wrap",
gap: 4,
containerType: "inline-size"
});
const Item = styled("div")(({ theme }) => ({
background: "#e4bebb",
width: "100%",
[theme.breakpoints.up("sm").replace("@media", "@container")]: {
width: "calc(50% - 4px)"
},
[theme.breakpoints.up("md").replace("@media", "@container")]: {
width: "calc(100% / 4 - 12px)"
}
}));
export default function GridSimple() {
return (
<Container>
{new Array(10).fill().map(() => (
<Item>test case</Item>
))}
</Container>
);
} https://codesandbox.io/s/pedantic-bardeen-b9ghp5?file=/src/App.js A few ideas:
But in any case, this is off-topic to this issue. This issue is about the Grid component. |
I am closing this issue. To use container queries, use I think we should not spend effort to make the Grid works with container queries, this would make the implementation more complex especially with Pigment CSS being static CSS. New component makes more sense. <Box sx={{ display: 'flex', gap: 2 }}>
<Box sx={{ width: { '@sm': '50%', '@md': '33.33%' } }}>…</Box>
</Box> |
This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue. Note @Mistes974 How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey. |
This is about having this built-in in the Grid component. |
Summary 💡
Hi, I started a project with react-splitter-layout and material ui library.
I would like to find a way to create responsive components, with material ui Grid or Box component
I encounter a problem with responsive, I would like my left panel to be responsive (use of xs / md / lg) with Grid component based on the size of the container (not window size), as you can see in the example below , this is not the case. It's use the viewport size. (I know it's normal because of media queries).
Examples 🌈
Here the code sample : https://codesandbox.io/s/material-demo-i04rr?file=/demo.js (recommended to open the rendering in a new tab to see the problem)
Motivation 🔦
In my project the user can open/close the right panel like a sidebar/drawer with a button located on the topbar. So, everything on the left should be responsive.(When sidebar is closed the left side == screen size) Just like on the codesandbox UI, they have a code part and a rendered part, the rendering is displayed inside an iframe and when you dragging in the middle the content adapts to different devices. I would like something similar but without using an iframe.
Actually, I'm using react-container-query, but it doesn't meet all of my needs.
The text was updated successfully, but these errors were encountered: