Reputation: 3021
I have a material ui snackbar which i need to display in middle of the screen. Below is the property which i am trying to pass to make it display center of the screen but its displaying at top of the screen.
anchorOrigin={{
vertical: "center",
horizontal: "center"
}}
https://codesandbox.io/s/snackbar-background-color-f37po is the example showcasing the issue. What's wrong here?
Upvotes: 12
Views: 15442
Reputation: 1
You can use the snackbar's root class and set the top property to 50% (MUI: v6)
<Snackbar
open={open}
autoHideDuration={600000}
onClose={onClose}
anchorOrigin={{ horizontal: 'center', vertical: 'top' }}
sx={{ '&.MuiSnackbar-root': { top: '50%' } }}>
</Snackbar>
Upvotes: 0
Reputation: 1
<Snackbar
open={snackbarOpen}
autoHideDuration={900} // Adjust the duration as needed
onClose={handleSnackbarClose}
anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
>
<SnackbarContent
style={{ backgroundColor: 'red' }}
message="No results found."
/>
</Snackbar>
Upvotes: -1
Reputation: 2252
To make it vertically align center. We can use sx
prop with height: 100%
on Snackbar component. Tested in MuiV5 and working fine.
<Snackbar
sx={{ height: "100%" }}
anchorOrigin={{
vertical: "top",
horizontal: "center"
}}
...
...
/>
Upvotes: 23