timolins / react-hot-toast

Smoking Hot React Notifications 🔥
https://react-hot-toast.com
MIT License
9.55k stars 313 forks source link

toast() with position absolute or fixed make the toast always opacity 0 #255

Closed QzCurious closed 1 year ago

QzCurious commented 1 year ago

I made a codesandbox for this here.

What I were trying to achieve is let toast follow mouse click position. So I need to set the position to absolute or fixed and { left: e.clientX, top: e.clientY }. Either setting position by className or style cause the toast element always opacity 0.

timolins commented 1 year ago

Hi there!

The problem comes from the ToastWrapper trying to determine the height of its content, which is not possible if it is set to position absolute. As long as there is no height, it assumes the content is not ready yet so it defaults to opacity 0.

https://github.com/timolins/react-hot-toast/blob/031a99c7f91fc04458dd43c6c2825aa745250c4c/src/components/toaster.tsx#L122-L136

If you want to give your toasts an absolute position you can either:

timolins commented 1 year ago

Related #229