Incompatibility of Material UI Grid in IE 11 - reactjs

I'm trying to achieve the following grid layout using the Grid component in Material UI.
I was able to achieve this layout in Chrome and Firefox using the following sample code, however in IE 11 all the grid items overlap and the textfields get expanded.
<Grid container direction='column' spacing={0}> // Grid 1 (Level0)
<Grid item xs={12}> // Grid 1 (Level1)
<Grid container direction='row' spacing={0}>
<Grid item xs={6}>
Logo
</Grid>
<Grid item xs={6}>
FormControl
</Grid>
</Grid>
</Grid>
<Grid item xs={12}> // Grid 2 (Level1)
<Grid container direction='column' spacing={0}>
<Grid item xs={12}> // Grid 1 (Level2)
<Grid container direction='row' spacing={0}>
<Grid item xs={12}>
<TextField/>
</Grid>
<Grid item xs={12}>
<TextField/>
</Grid>
</Grid>
</Grid>
<Grid item xs={12}> // Grid 2 (Level2)
<Grid container direction='row' spacing={0}>
<Grid item xs={6}>
<TextField />
</Grid>
<Grid item xs={6}>
<TextField />
</Grid>
</Grid>
</Grid>
</Grid>
</Grid>
<Grid item xs={12}> // Grid 3 (Level1)
<Grid container direction='row' spacing={0}>
<Grid item xs={6}>
Label
</Grid>
<Grid item xs={6}>
Label
</Grid>
</Grid>
</Grid>
</Grid>
Please let me know where am I going wrong!

According to the Material UI documentation, Material UI supports IE 11.
However, the Grid formatting issues as you describe them are a documented problem with a fix. The issues are a result of a Grid item not having the flex size set. In Chrome you can just use <Grid item>, but for IE you need to explicitly set the flex size <Grid item xs=12>.
How does this relate to you?
In your case it looks like your child <Grid container> components should also be <Grid item> components. That is, they should be of the form <Grid container item>, but they should also have the flex size set <Grid container item xs=12>.
Below is a sample snippet:
<Grid container>
<Grid item xs={12}>
<Grid container item xs={12}>
<Grid item xs={6}>
Logo
</Grid>
<Grid item xs={6}>
FormControl
</Grid>
</Grid>
</Grid>
</Grid>

Related

MUI Grid xs item doesn't shrink

I've created a small Dashboard in order to view achievements of some sort (won't get into details). The page consists in small boxes with certain information and to make them responsive I've used MUI Grid.
<Box>
<Grid container spacing={3}>
<Grid item xs={12} md={6} lg={6}>
<SelfNumberOfQuizzes />
</Grid>
<Grid item xs={12} md={6} lg={6}>
<SelfPointsInPeriod period={period} />
</Grid>
</Grid>
<Grid container spacing={3} mt={1.5}>
<Grid item xs={12} md={6} lg={6}>
<SelfNumberOfQuizzesByDifficulty />
</Grid>
<Grid item xs={12} md={6} lg={6}>
<SelfPointsByDifficultyInPeriod period={period} />
</Grid>
</Grid>
<Grid container spacing={3} mt={1.5}>
<Grid item xs={12} md={12} lg={12}>
<SelfAnswersByDifficulty />
</Grid>
</Grid>
</Box>
The page looks good and it works just fine when trying to shrink when lg or md (the inside items shrinks as well to be fully visible). However, once the page is small enough to use xs prop, the items don't shrink anymore, the width looks fixed.
First picture -> MD
Second picture -> XS
You can see the horizontal scroll bar when it starts to be XS. The components within each grid item don't have width specified.

MaterialUI - Indepdendent Grids next to each other?

I have a Grid container and two "sub-containers" each taking half the space of the parent grid. I want to stack items of different heights on each of the sub-containers, but I'm having a problem with one side's height affecting the other.
The code is extremely simple:
<Box sx={{ flexGrow: 1 }}>
<Grid container spacing={3}>
<Grid item container xs={6}>
<Grid item xs={12}>
<Item>Short items</Item>
</Grid>
<Grid item xs={12}>
<Item>Short items</Item>
</Grid>
<Grid item xs={12}>
<Item>Short items</Item>
</Grid>
</Grid>
<Grid item container xs={6}>
<Grid item xs={6}>
<Item style={{ height: "450px" }}>Tall item</Item>
</Grid>
</Grid>
</Grid>
</Box>
And also a Codesandbox forked from the documentation's. The result I want is the items on the left stacking right on top of each other.
You can add alignContent="baseline" to your left Grid container like:
<Grid item container xs={6} alignContent="baseline">
You can take a look at this sandbox for a live working example of this usage.

how to use grid material ui?

I have a component whose grid looks like this:
component Region:
<Grid container spacing={10} >
<Grid item xs={4} ></Grid>
<Grid item xs={4} ></Grid>
<Grid item xs={4} ></Grid>
<Grid item xs={4} ></Grid>
<Grid item xs={4} ></Grid>
</Grid>
And I use this component in another component, which also has a series of grids..component address:
<Grid container spacing={10}>
<Grid item>
<form >
<Region></Region>
<Grid container spacing={10}>
<Grid item xs={4} ></Grid>
</Grid>
<form >
</Grid>
</Grid>
What I want is for this gride to be a continuation of the other grids, but for me it goes to the next line.
What should I do to get the grid inside the address component in the following component region?
You need to have all grid items in the same grid container. So:
remove the top container and item, because you only got one item and it doesn't make sense.
remove the container from Region component and use a Fragment
remove the container from Address
Region:
<>
<Grid item xs={4}>1</Grid>
<Grid item xs={4}>2</Grid>
<Grid item xs={4}>3</Grid>
<Grid item xs={4}>4</Grid>
<Grid item xs={4}>5</Grid>
</>
Form:
<form>
<Grid container spacing={10}>
<Region />
<Grid item xs={4} >6</Grid>
</Grid>
</form>

Change Grid item column order on small screens

I'm attempting to have a grid looking like this for larger displays:
and this for smaller sizes:
Currently the skeleton of my grid is succinctly like this:
<Fragment>
<Grid container spacing={3}>
<Grid item xs={12} md={6}>
<img src={img1} />
</Grid>
<Grid item xs={12} md={6}>
<Paper>Text Content 1...</Paper>
</Grid>
</Grid>
<Grid container spacing={3}>
<Grid item xs={12} md={6}>
<Paper>Text Content 2...</Paper>
</Grid>
<Grid item xs={12} md={6}>
<img src={img2} />
</Grid>
</Grid>
</Fragment>
How can I do such as in mobile view (width 12) the first Grid item from the second Grid container (Text content 2) displays after (below) the image?
Use like this:
<Grid container>
<Grid spacing={3} container item xs={12} md={12}>
<Grid item xs={12} md={6} className={classes.item}>
<img
width="50px"
src="https://cdn3.vectorstock.com/i/1000x1000/37/37/simple-cartoon-a-cute-bear-vector-18823737.jpg"
alt="abc"
/>
</Grid>
<Grid container item xs={12} md={6} className={classes.item}>
<Paper>Text Content 1...</Paper>
</Grid>
</Grid>
<Grid container item spacing={3} xs={12} md={12} className="flexgrid">
<Grid container item xs={12} md={6} className={classes.item}>
<Paper>Text Content 2...</Paper>
</Grid>
<Grid container item xs={12} md={6} className={classes.item}>
<img
width="50px"
src="https://cdn3.vectorstock.com/i/1000x1000/37/37/simple-cartoon-a-cute-bear-vector-18823737.jpg"
alt="abd"
/>
</Grid>
</Grid>
</Grid>
SOURCE
PREVIEW
for re-order added:
<Grid container item spacing={3} xs={12} md={12} className="flexgrid">
and css :
#media screen and (max-width: 720px) {
.flexgrid{
flex-direction: column-reverse
}
}

Better way to position elements in a grid

I try to have a header on my application, where the left item (A) is aligned to the left side of the header, the second item (B) is in the center of the header and the third item is aligned to the right.
I tried a lot and found out that only this worked for me
const AppHeader = () => {
return(
<Grid container
alignItems="baseline"
>
<Grid item xs={4}>
<Grid container justify="flex-start">
A
</Grid>
</Grid>
<Grid item xs={4}>
<Grid container justify="center">
B
</Grid>
</Grid>
<Grid item xs={4}>
<Grid container justify="flex-end">
C
</Grid>
</Grid>
</Grid>
)
}
I think this is a ugly solution, because putting a container inside an item seems so unnecessary to me. Especially if we consider that this container has no grid items. I would really like to tell the item to align its content to a position. It would be better if this solution could be more like his:
const AppHeader = () => {
return(
<Grid container
alignItems="baseline"
>
<Grid item xs={4} justify="flex-start">
A
</Grid>
<Grid item xs={4} justify="center">
B
</Grid>
<Grid item xs={4} justify="flex-end">
C
</Grid>
</Grid>
)
}
Is there a way to do something similar like that?
Assuming you are using material-ui Grid component. You can do something like this
<Grid container direction="row" justify="space-between" alignItems="center">
<div>A</div>
<div>B</div>
<div>C</div>
</Grid>
CodeSandbox Link: https://codesandbox.io/s/small-haze-1wvtr

Resources