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
Related
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
<Box sx={{
background: 'blue', width: '700px', height: '700px', borderRadius: 5
}}>
<img src={house} alt="" sx={{
maxWidth: '100%', maxHeight: '100%', objectFit: 'cover'
}}></img>
</Box>
</Box
I have tried to set the border to none and also the box Shadow to none, nothing works. The lines only appear when the modal body is clicked. I omitted the modal styling code because it only contains flex styling, etc.
The code below is the implementation for the modal:
<Modal aria-labelledby="transition-modal-title" aria-describedby="transition-modal-description"
className={classes.modal} open={state.open} onClose={handleClose} closeAfterTransition BackdropComponent={Backdrop}
BackdropProps={{
timeout: 500, classes: { root: classes.backDrop }
}}
>
<Fade in={state.open}>
<Column gap={2} style={{width:'50%',height:'70%'}}>
<Row
style={{width: '100%',position:'relative',left:'5%',marginTop:'2%', boxShadow:'none',border:'none' }}
className={classes.modal}
>
<Item bgcolor="background.paper" position={'middle'} width={345.6} style={{borderRadius:'4px'}}>
{/***code cut out**/}
<br/>
<Button
style={{
width: '60%', backgroundColor: 'white', marginLeft:'20%',
color: "black", textTransform: 'none', fontSize: '10px', height:'12px'
}} variant="text"
onClick={handleClose}
><b>Return to Nike store</b>
</Button>
</Item>
<IconButton onClick={handleClose} style={{
position: 'relative', top: '-60%', left: '7.7%', transform: 'translate(-50%, -50%)',
}}>
<ClearOutlinedIcon style={{
color:'#000',border:'1px solid #fff',borderRadius:'100%',background:'#fff',
width: '35px', height:'35px'
}} />
</IconButton>
</Row>
<Row
style={{width: '100%'}}
className={classes.modal}
>
<Item position={'middle'} width={345.8}>
<Typography style={{color: "#fff", display: 'flex',
fontSize: '10px', justifyContent: 'center', maxWidth:'60%', marginLeft:'15%'
}}>
<Lock style={{ fontSize: '14px', justifyContent: 'center', fontFamily: 'Comfortaa'}} />
payments by <b>SlashIt</b>
</Typography>
</Item>
</Row>
<Row style={{width: '100%'}} className={classes.modal} >
<Item position={'middle'} width={345.8}>
<Typography style={{color: "#fff", display: 'flex',
fontSize: '10px', justifyContent: 'center', maxWidth:'60%', marginLeft:'17%',
marginTop:'-2%'
}}>
Terms Privacy
</Typography>
</Item>
</Row>
</Column>
</Fade>
</Modal>
I accidentally found a solution to this problem while resolving similar problems on a different project.
A pseudo-selector should be added be added to the content of the classes.modal styling:
...,
modal: {
...,
'&:focus' : {
outline: 'none !important';
}
}
The above snippet makes sure that when the modal is in focus, the outline value will be set none whether or not there's an overriding code.
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
i have tries so many times but when usting different component in scroll body it just not adjust on to the content therefor some content are not included in scrollView. it has cut as shown as in the image..any sugession for fix..?
sample code i used
const height = Dimensions.get('window').height;
const width = Dimensions.get('window').width;
some code in the class
<ScrollView>
<View style={styles.middleview}>
<TextInput
style={styles.textinputs}
placeholder="Location"
placeholderTextColor='grey'
/>
<TouchableOpacity>
<Text style={{fontSize:20}}>
Post Ad
</Text>
</TouchableOpacity>
</view>
</scrollView>
styles used
textinputs: {
backgroundColor: 'white',
paddingTop: '2%',
paddingBottom: '2%',
paddingLeft: '4%',
paddingRight: '4%',
width: '90%',
borderRadius: 50,
margin: '3%',
color: 'grey',
height: '8%',
borderColor: 'white',
borderWidth: .8,
elevation: 10,
middleview:{
backgroundColor: 'lightblue',
flex: 1,
height: Dimensions.get('window').height,
width: Dimensions.get('window').width,
alignItems: 'center',
justifyContent: 'center'
}
here is the image below its cut the component scroll view is ended in the middle of components..
Add style to the scrollview using "contentContainerStyle"
Working eg: https://snack.expo.io/#msbot01/rebellious-cookie