Skip to content
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

Snackbar props not honored on smaller screens #367

Closed
rzmz opened this issue Apr 9, 2021 · 10 comments
Closed

Snackbar props not honored on smaller screens #367

rzmz opened this issue Apr 9, 2021 · 10 comments

Comments

@rzmz
Copy link

rzmz commented Apr 9, 2021

I think a screenshot of notistack documentation website will best describe the problem:

Screenshot 2021-04-09 at 13 06 05

The notification appears to the left of the screen, instead should be in center as selected.

@raulgg
Copy link

raulgg commented Apr 9, 2021

I've noticed this issue as well. It seems to be a CSS problem, you can add a class to the providers configuration to bypass this issue.

For the case in your screenshot I would do the following:

const useStyles = makeStyles((theme) => ({
  containerTopOffset: {
    display: "flex",
    alignItems: "center",
  }
}));
<SnackbarProvider
  maxSnack={3}
  anchorOrigin={{ vertical: "bottom", horizontal: "center" }}
  classes={{
    anchorOriginBottomCenter: classes.containerBottomCenter
  }}
>
  <MyApp />
</SnackbarProvider>

@rzmz
Copy link
Author

rzmz commented Apr 9, 2021

Thanks! Will try that.

@iamhosseindhv
Copy link
Owner

iamhosseindhv commented Apr 9, 2021

I noticed this issue and the fix will be published soon. In the meantime, it's the wrapperInner element of Collapse that you need to customise.

const useStyles = makeStyles((theme) => ({
  container: {
    [theme.breakpoints.down('xs')]: {
      '& .MuiCollapse-container, .MuiCollapse-container .MuiCollapse-wrapper .MuiCollapse-wrapperInner': {
         width: "100%" // occupy full-width on xs screens
      }
    }
 },
}));


const classes = useStyles();
return (
<SnackbarProvider
  maxSnack={3}
  anchorOrigin={{ vertical: "bottom", horizontal: "center" }}
  classes={{
    containerRoot: classes.container
  }}
>
  <MyApp />
</SnackbarProvider>
)

@rzmz
Copy link
Author

rzmz commented Apr 10, 2021

I unfortunately had no luck with neither of those solutions at first but when I changed
anchorOriginBottomCenter: classes.containerBottomCenter
to point to correct classname containerTopOffset, solution by @raulgg works! Thanks!

@dmastrorillo
Copy link

I noticed this issue and the fix will be published soon. In the meantime, it's the wrapperInner element of Collapse that you need to customise.

const useStyles = makeStyles((theme) => ({
  container: {
    [theme.breakpoints.down('xs')]: {
        '& > .MuiCollapse-container > .MuiCollapse-wrapper  > .MuiCollapse-wrapperInner ​': {
           width: '100%',  // occupy full-width on xs screens
        },
    }
 },
}));


const classes = useStyles();
return (
<SnackbarProvider
  maxSnack={3}
  anchorOrigin={{ vertical: "bottom", horizontal: "center" }}
  classes={{
    containerRoot: classes.container
  }}
>
  <MyApp />
</SnackbarProvider>
)

This didn't work for me at first. However after a minor modification it is now working! Thanks for that!

const useStyles = makeStyles((theme) => ({
  container: {
    [theme.breakpoints.down("xs")]: {
      "& .MuiCollapse-container, .MuiCollapse-container .MuiCollapse-wrapper .MuiCollapse-wrapperInner": {
        width: "100%" // occupy full-width on xs screens
      }
    }
  }
}));

@aeharding
Copy link

Here's my hotfix (note: only for 100% 📱 projects, 🚫 🖥):

  .MuiCollapse-wrapperInner {
    // notistack broke mobile snackbar widths
    // remove once fixed: https://github.com/iamhosseindhv/notistack/issues/367
    width: 100% !important;
  }

@iamhosseindhv
Copy link
Owner

This is fixed in the latest release v1.0.6. I'd appreciate if one of you could confirm.

@dmastrorillo
Copy link

dmastrorillo commented Apr 18, 2021

@iamhosseindhv I just tested on mine and I am getting the same problem :(

I just had a look through the inspector and I can see width:100% being set however it is overwritten to width:"auto" by the className .SnackbarItem-collapseWrapperInner-63

Screen Shot 2021-04-19 at 3 00 44 am (2)

@JanderSilv
Copy link

JanderSilv commented Apr 19, 2021

I guess the problem was solved on v.1.0.6.

Before:
image

Now on v.1.0.6:
image

@aeharding
Copy link

I also confirm 1.0.6 is working for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants