react-hot-toast icon indicating copy to clipboard operation
react-hot-toast copied to clipboard

toast.custom displays toast briefly after exit animation

Open lambo81 opened this issue 2 years ago • 4 comments

Following the toast.custom example on the site, my toast entry animation plays, the exit animation plays, but then after the exit animation is done and the toast has faded out, the toast suddenly appears again in full opacity for a moment before disappearing completely. I am using "@material-tailwind/react": "0.3.4" and "react-hot-toast": "^2.2.0",

here is my code:

toast.custom((t) => 
                        (<div className={`bg-white px-6 py-4 shadow-md rounded-full ${
                                t.visible ? 'animate-enter' : 'animate-leave'
                              }`}>Hello TailwindCSS! 👋</div>) 
                      );

I added to my tailwind.config.css

module.exports = {
  content: [
    './pages/**/*.{js,ts,jsx,tsx}',
    './components/**/*.{js,ts,jsx,tsx}',
  ],
  theme: {
    extend: {
      animation: {
        enter: 'fadeInRight 300ms ease-out',
        leave: 'fadeOutLeft 300ms ease-in',
      },
      keyframes: {
        fadeInRight: {
          '0%': {
            opacity: '0',
            transform: 'translate(2rem)',
          },
          '100%': {
            opacity: '1',
            transform: 'translate(0)',
          },
        },
        fadeOutLeft: {
          '0%': {
            opacity: '1',
            transform: 'translate(0)',
            
          },
          '100%': {
            opacity: '0',
            transform: 'translate(2rem)',
          },
        },
      },
    },
  },
  plugins: [],
}

lambo81 avatar Mar 26 '22 18:03 lambo81

Same error here :(

TrejoCode avatar Mar 31 '22 22:03 TrejoCode

Just add the forwards animation direction property like so: leave: 'fadeOutLeft 300ms ease-in forwards',

For reference, see this line for how react-hot-toast does it: https://github.com/timolins/react-hot-toast/blob/main/site/tailwind.config.js#L24

BrandLibel avatar Apr 29 '22 23:04 BrandLibel

Thanks! Hopefully the documentation can be fixed for others

clam61 avatar May 07 '22 15:05 clam61

@timolins would be nice to fix the example here https://react-hot-toast.com/docs/styling (the last section, Change enter and exit animations)

secretwpn avatar Apr 25 '23 07:04 secretwpn