Cogoport / cogo-toast

Beautiful, Zero Configuration, Toast Messages for React. Only ~ 4kb gzip, with styles and icons
https://cogoport.github.io/cogo-toast
MIT License
673 stars 1 forks source link

Doesn't close when interacting globally #51

Closed debotos closed 4 years ago

debotos commented 4 years ago

My code snippet,

// Session Timeout | Token Expired
const { hide } = cogoToast.info('Session expired. Please login again!', {
    hideAfter: 0, // 0 to disable auto-hiding of the toast
    onClick: () => {
        hide()
    }
})

My expectation is after seeing this notification if the user clicks anywhere on the page the notification should close. But currently, it's only closing when the user clicks on it neither it stays forever until a page refresh. And I don't want to close this message if the user is not interacting with the app. Any solution for this situation? Thanks.

debotos commented 4 years ago

I found the solution. Added a click listener.

componentDidMount() {
    window.addEventListener('click', this.handleMouseClick)
}
componentWillUnmount() {
    window.removeEventListener('click', this.handleMouseClick)
}
handleMouseClick = () => {
    this.props.hideNotification()
}