Div not scrolling when items overflow - css

I have the following code for a modal using Mui Modal.
Everything works except when I add more items to the cart. When this happens and the minHeight exceeds 500, it continues to 100vh and then stops and only shows 5 items, even if there are well over 5 items in the cart.
I gave the parent div overflow: auto, overflow: scroll, overflowY: scroll but it still doesn't work, any ideas?
<Modal
open={open}
onClose={handleClose}
aria-labelledby="modal-modal-title"
aria-describedby="modal-modal-description"
>
<div
style={{
minHeight: "500px",
width: "500px",
backgroundColor: "gray",
gap: "10px",
display: "flex",
flexDirection: "column",
overflowY: "scroll",
}}
>
{cart.map((displate) => {
return (
<Card
sx={{
height: "200px,
display: "flex",
padding: "10px",
gap: "10px",
backgroundColor: "black",
margin: "10px",
}}
>
<div
style={{
backgroundImage: `url(${displate.img})`,
backgroundSize: "cover",
backgroundPosition: "center",
height: "150px",
width: "120px",
}}
></div>
<div
style={{
display: "flex",
flexDirection: "column",
justifyContent: "center",
color: "white",
}}
>
<Typography>Name: {displate.name}</Typography>
<Typography>Size: {displate.size}</Typography>
<Typography>Finish: {displate.finish}</Typography>
<Typography>Frame: {displate.frame}</Typography>
<Typography>Quantity: {displate.quantity}</Typography>
</div>
</Card>
);
})}
</div>
</Modal>

The reason it wasn't working was because each card inside the map function didn't have a minHeight so they were just adjusting their heights to fit inside the container.
Adding both a maxHeight of 100vh to the parent container and a minHeight of 150px for each element fixed the issue

Related

Mui Button inside link not occupying entire height

I have a button inside a link inside a div that's not occupying the entire height of the div so what ends up happening is that the link gets clicked but not the button. I tried giving the button a height of 100% and removing padding but it doesn't seem to work.
Here's the element:
<div
style={{
display: "flex",
gap: "20px",
flexDirection: "column",
}}
>
<Link
to="/regions"
style={{
pointerEvents: regions > 0 ? "none" : "auto",
lineHeight: "0rem",
color: "black",
}}
>
<Button
variant="outlined"
sx={{
width: "400px",
color: "white",
"&:disabled": {
backgroundColor: "rgba(255,255,255,0.1)",
color: "white",
},
}}
onClick={() => handleClick("regions")}
disabled={regions > 0 ? true : false}
>
Region Test
</Button>
</Link>
{regionScore > 0 && (
<Box sx={{ width: "400px" }}>
<LinearProgress
color="success"
variant="determinate"
value={regionScore}
sx={{
backgroundColor: "transparent",
border: "1px solid black",
height: "20px",
borderRadius: "20px",
}}
/>
</Box>
)}
</div>
Any ideas?

Material UI Modal being dimmed by backdrop

I have a modal that is supposed to pop up to show the status of a transaction going through on my website. It works fine other than the fact that the backdrop dimming effect is also applied on top of the modal. My modal is supposed to be white but it ends up being a sort of dark gray. I'm not sure what I'm doing wrong.
Here is the stying for the modal
const modalStyle = {
position: 'absolute' as 'absolute',
top: 0,
left: 0,
width: "80%",
marginLeft: "auto",
marginRight: "auto",
marginTop: "150px",
marginBottom: "150px",
bgcolor: 'white',
boxShadow: 24,
p: 3,
borderRadius: "25px"
}
And here is the HTML for it:
<Modal
open={open}
aria-labelledby="modal-modal-title"
aria-describedby="modal-modal-description"
sx={modalStyle}
>
{!done ? (
<div style={{ display: "flex", flexDirection: "column", height: "100%", alignItems: "center" }}>
<h1 style={{ fontSize: "50px", textAlign: "center", fontWeight: "700" }}>Transaction Loading...</h1>
<Box style={{ display: 'flex', width: "300px", height: "300px", justifyContent: "center", }}>
<CircularProgress style={{ marginTop: "50px" }} size={150} />
</Box>
</div>) : (
<div style={{ display: "flex", flexDirection: "column", height: "100%", alignItems: "center", zIndex: "25" }}>
<h1 style={{ fontSize: "50px", textAlign: "center", fontWeight: "700" }}>Transaction Completed!</h1>
<svg className={styles.animatedCheck} viewBox="0 0 24 24">
<path d="M4.1 12.7L9 17.6 20.3 6.3" fill="none" />
</svg>
</div>)}
</Modal>
I don't really know what is going wrong. It's weird because I use a very similar modal declaration at another point in my project and it works completely as expected.
The Modal component simply renders whatever children you pass to it in front of a backdrop component -- it's up to you to style the children. This issue is happening because, in your code, you're attempting to style the Modal root, not its children.
To fix it, wrap your content in another element onto which you can apply your styles and then move your modalStyle styling to that element. For my example, I wrapped them in a Box:
<Modal
open={open}
aria-labelledby="modal-modal-title"
aria-describedby="modal-modal-description"
>
<Box sx={modalStyle}> {/* Moved here */}
...
</Box>
</Modal>
Which produced:
Working CodeSandbox: https://codesandbox.io/s/sad-christian-de6m9k?file=/demo.tsx

I am trying to fit the image inside the div in react mui i made it's maxWidth & maxHeight properties to 100% and object fit cover and it's not working

<Box sx={{
background: 'blue', width: '700px', height: '700px', borderRadius: 5
}}>
<img src={house} alt="" sx={{
maxWidth: '100%', maxHeight: '100%', objectFit: 'cover'
}}></img>
</Box>
</Box

Align text vertically center in Flexbox in react native

I want to align text vertically inside flex container.I used following codes with aligncontent , justifycontent etc like below.
<Col
size={1}
style={{
padding: 10,
justifyContent: "center",
alignContent: "center",
backgroundColor: "orange",
borderRightColor: "#373738",
borderWidth: 1,
}}
>
<Text
style={{
flex: 1,
backgroundColor: "red",
fontSize: 14,
alignItems: "center",
textAlign: "center",
color: "#fff",
}}
>
{ago}
</Text>
</Col>
But none of them works , Please look below. Still the text is not aligned center vertically.
Try setting style in Text to be
display: flex;
align-items: center;
height: 100%;

Material ui / typography and button on the same line

I am struggling to align a button and a <Typography> component on the same line:
Here is what I have so far:
<Grid item lg={12} md={12} sm={12} xs={12} className={classes.register}>
<Typography noWrap className={classes.typoText} variant="subtitle2">
text1
</Typography>
<ButtonBase className={classes.labelForgot} disableFocusRipple="false" disableRipple="false" centerRipple="false">
<Typography noWrap className={classes.labelForgot} variant="subtitle2">
text2
</Typography>
</ButtonBase>
</Grid>
My styles:
labelForgot: {
color: 'rgba(20, 176, 12,0.9)',
backgroundColor: 'transparent',
paddingLeft: 2,
'&:hover': {
color: 'rgb(57, 232, 48)',
backgroundColor: 'transparent',
}
},
root: {
backgroundSize: 'cover',
backgroundPosition: 'center center',
backgroundRepeat: 'no-repeat',
minHeight: '100vh',
justifyContent:'center',
overflow: 'hidden',
},
gridMain: {
margin: '0 auto',
maxWidth: 300,
},
Basically I have a <div> that allows a height of ยด100%`.
For the container I use css grid main.
Here is the result
how to align horizontal icon and text in material ui
Check this page. I was stuck on the same problem... The suggested solution is wrapping the items with a div...
<div style={{
display: 'flex',
alignItems: 'center'
}}>
<Typography noWrap className={classes.typoText} variant="subtitle2">
text1
</Typography>
<ButtonBase className={classes.labelForgot} disableFocusRipple="false"
disableRipple="false" centerRipple="false">
<Typography noWrap className={classes.labelForgot} variant="subtitle2">
text2
</Typography>
</ButtonBase>
</div>
I tried to do it with Grids as well from Material UI but was having trouble with a header and buttons

Resources