teodosii / react-notifications-component

Delightful and highly customisable React Component to notify your users
https://teodosii.github.io/react-notifications-component/
MIT License
1.27k stars 73 forks source link

auto dismiss not working (anymore) #115

Closed MichaMican closed 2 years ago

MichaMican commented 3 years ago

I'm using this library in my project.

store.addNotification({
  ...notification,
  dismiss: {
    duration: 2000,
    onScreen: true
  }
})

Everything besides the autodismiss is working as expected. I tried to fix it but then i realized that it does not work on the demo page (where a autodismiss of 5000ms is set) as well. Is this a known issue or am I doing something wrong? I have imported the animate.css (v4) css file.

MichaMican commented 3 years ago

I just realized it only happens if onScreen is set to true. I'm using a custom content:

store.addNotification({
    content: <InlineMessage children={notification.message} type={notification.type}/>,
    message: notification.message,
    type: notification.type,
    insert: "top",
    container: "top-right",
    animationIn: ["animate__animated", "animate__fadeIn"],
    animationOut: ["animate__animated", "animate__fadeOut"],
    dismiss: {
    duration: ((notification.autoDismiss ?? 12) * 1000),
    onScreen: true,
    }
});
teodosii commented 3 years ago

Seems to be skipped. I think I took the decision to either dismiss by duration or by click, not by both. image

Will go fixed in the next release (don't know when that'll happen)

Demo page uses infinite duration (set to 0).

teodosii commented 2 years ago

I don't recall publishing a fix for this but I just tested this and it works accordingly. The dismiss property is an object where you can attach click (boolean), the default for that is true, unless specified otherwise it should always be dissmisable by clicking since the clicking doesn't care whether it's onScreen, custom content or anything else, it just looks for that property.

image

@MichaMican

If this is still an issue feel free to reopen it, I just didn't notice anything with it.

const object: iNotification = {
  content: <h1>Hello</h1>,
  type: "success" as any,
  insert: "top" as any,
  container: "top-right" as any,
  animationIn: ["animate__animated", "animate__fadeIn"],
  animationOut: ["animate__animated", "animate__fadeOut"],
  dismiss: {
    duration: 3000,
    onScreen: true,
  } as any
}

I used the code above to replicate your issue.