fkhadra / react-toastify

React notification made easy 🚀 !
https://fkhadra.github.io/react-toastify/introduction
MIT License
12.34k stars 676 forks source link

Allow the close button to be hidden when the toast is set to autoClose #953

Closed illandril closed 1 year ago

illandril commented 1 year ago

Do you want to request a feature or report a bug? Feature

What is the current behavior? When closeButton is a function, the values passed in are closeToast, type, and theme.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your CodeSandbox (https://codesandbox.io/s/new) example below:

What is the expected behavior? closeButton is also passed the autoClose value.

We'd like this value so we can hide the close button in situations where the toast will auto close, so alternative solutions that allow for that would also be acceptable (ex. a new "hideCloseButtonOnAutoClose" prop).

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React? All.

jaisaichand commented 1 year ago

I would like to work on this if someone haven't taken this already

fkhadra commented 1 year ago

@illandril not sure to understand well. You can pass false to closeButton props if you want to hide it. see https://fkhadra.github.io/react-toastify/use-a-custom-close-button-or-remove-it/#remove-it

illandril commented 1 year ago

I must have typo'd closeButton before when trying to use it as an option for a toast instead of on the container, because I had tried that and it didn't work before.

I've tried it again and it is working, so that works as a "good enough" solution.

It would still be nice to have it passed in as a prop to closeButton, so I only need to set closeButton on the container instead of needing to override it for every toast that has an autoClose... but that is definitely just a low-priority "nice to have".

fkhadra commented 1 year ago

@illandril you can already pass closeButton to the container :) and override it by toast when needed.

illandril commented 1 year ago

What you can't do, and what I was asking for, is a way to set a closeButton and autoClose: 5000 on the container, and then set only autoClose (as opposed to both autoClose and closeButton) on the toasts as needed, having the close button show if and only if autoClose is false.

The benefits being...