React-toastify: Animations not working, autoClose not working

Created on 21 Sep 2017  路  16Comments  路  Source: fkhadra/react-toastify

Oddly, animations are not working for me at all. When the toast appears, there is no animation. Similarly, when I manually close the toast, there is an abrupt close with no animation. And because autoClose is dependent on the animation, the toast will never close until triggered manually.

I have the CSS file referenced correctly, and styling seems to work otherwise. My implementation is as follows:

Container:

<ToastContainer
    position="top-right"
    type="error"
    autoClose={4000}
    hideProgressBar={false}
    closeOnClick={true}
    pauseOnHover={true}
/>

Trigger code (tried placing this in various areas in my code with the same result):

toast('message', {
    type: toast.TYPE.ERROR,
    autoClose: 3000,
    hideProgressBar: false,
    pauseOnHover: true,
});

this

I've tried every variation of settings to no avail. This was attempted using the newest versions of Chrome and Safari. What could be going wrong here?

Most helpful comment

I have CSS modules in my project, and just copied all CSS from the module and added :global prefix to each one. I do not have animations nor autoClose working.

All 16 comments

@emadow I don't have the issue at all. I'm also using chrome and safari latest version. Do you see any things when you open the developer tools ?

@fkhadra no errors in the console. Very puzzling.

Ack. Seems to be the result of how webpack was dealing with my imports -- the css @keyframes were not accessible globally.

Ow I'm glad you fixed it.

@emadow Can you please share your fix? I've stuck with this too.

I'm also having this issue

I have CSS modules in my project, and just copied all CSS from the module and added :global prefix to each one. I do not have animations nor autoClose working.

I have the same problem as @JustFly1984 , autoclose and animation are not working because I had to put the css rules under :global approach. Does someones have a fiz already?

Same problem for me, +1

Hello,

It would be nice to reproduce the bug via codesandbox. Anyone know how to do this ?

I could, but is it possible to update webpack configuration with codesandbox ?

Here the code : https://codesandbox.io/s/z252xzmvrl

CSS for toasts does not work on codesandbox because the webpack.config.js is not used (so the modules are not activated by default for css-loader). I don't know if it is possible to configure webpack on codesandbox...

In my project on my PC, the CSS of the toast box works well, but not the autoclose or animations.
If I remove modules option in css-loader and import globally like in your documentation, autoclose and animations work.

In my case I use CSS modules, so I can鈥檛 just import styles from
node_modules. I鈥檝e copied css, and added global prefix to each class name

Me too facing the same issue. Does anyone know how to fix this webpack issue . The progressbar and auto close is not working

I was using Next.js with CSS Modules and faced a similar issue. I solved it by tweaking the CSS file as follows:

Initial:

@keyframes Toastify__slideInUp {
  from {
    transform: translate3d(0, 110%, 0);
    visibility: visible;
  }

  to {
    transform: translate3d(0, 0, 0);
  }
}

Final (wrapping the animation name with :global()):

@keyframes :global(Toastify__slideInUp) {
  from {
    transform: translate3d(0, 110%, 0);
    visibility: visible;
  }

  to {
    transform: translate3d(0, 0, 0);
  }
}

Source: css-modules#115

I had to manually add :global to all the keyframes, apart from a common :global for the other classes. I have made the edited stylesheet with all the :global's added in this gist so that you don't have to go through the same pain 馃槄

@fkhadra Can you please add this to the documentation? It might be helpful for people using CSS Modules.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JaLe29 picture JaLe29  路  5Comments

LouisCuvelier picture LouisCuvelier  路  3Comments

shirbr510 picture shirbr510  路  5Comments

fkhadra picture fkhadra  路  3Comments

JakubKoralewski picture JakubKoralewski  路  4Comments