Closed clam61 closed 2 years ago
I guess it's something to do with Tailwind JIT plus toasts rendering. Try to add "animate-enter" somewhere else on the page (in addition to toast itself) and see what happens. Where "code to launch a toast" is located, in the components folder?
Try adding the forwards
keyword to your animations:
animation: {
enter: 'enter 200ms ease-out forwards',
leave: 'leave 200ms ease-in forwards',
},
This prevents the animation from reseting after they are done. Without it will jump from opacity: 0
to opacity: 1
again.
Bonus: You can also use TailwindCSS to create your animations, by using HeadlessUI's <Transition/>
component.
You can find an example here: https://codesandbox.io/s/react-hot-toast-tailwindcss-headless-ui-qvjri?file=/src/App.js
Instead of using toast.custom()
, I'm replacing the default toast renderer – which might be the behaviour you want.
Hi. I tried adding forwards to both, but it did not help. The problem is not the jumping, but that the leave animation doesn't play at all. Is there a reason my react toast is not behaving the same as the demo code?
There is also the padding problem. Suddenly it resolved itself, i dont know why.
I guess it's something to do with Tailwind JIT plus toasts rendering. Try to add "animate-enter" somewhere else on the page (in addition to toast itself) and see what happens. Where "code to launch a toast" is located, in the components folder?
yeah, i tried that. animate-enter and animate-leave function without issue when used outside of a toast
`
I guess it's something to do with Tailwind JIT plus toasts rendering. Try to add "animate-enter" somewhere else on the page (in addition to toast itself) and see what happens. Where "code to launch a toast" is located, in the components folder?
yeah, i tried that. animate-enter and animate-leave function without issue when used outside of a toast
Could you reproduce that issue in a sandbox? I've just made this leave-enter animation in my current project and it works without the issues you mentioned. In my case, it was I tried to create the component in /lib folder, out of the default
content: [
'./pages/**/*.{js,ts,jsx,tsx}',
'./components/**/*.{js,ts,jsx,tsx}',
],
the animation isnt the problem. because i think i took it off the github repo for hot toast examples. it must be with my config or something else is interfering.
you brought up an interesting point. what is the "content" section in tailwind config? i also call toast.custom from a file inside ./lib
i have an idea what it is--im guessing i need to add
content: [
'./pages/**/*.{js,ts,jsx,tsx}',
'./components/**/*.{js,ts,jsx,tsx}',
'./lib/**/*.{js,ts,jsx,tsx}',
],
looks like that was the issue. next time i wont gloss over parts of the config file i dont undrstand. thanks everyone.
@timolins I think this one is resolved.
I can make this custom toast, and the "enter" animation plays, but the "leave" animation does not. When I click the button on the toast, there is a short delay and then the toast disappears without the animation.
I have confirmed that the animations work, by using them on divs in a page.
The second problem I have is that if I specify p-5 for padding, the padding becomes 0. However, p-4 works.
Setup:
my code to launch a toast
tailwind config