Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toast Ref OnClose, OnClick #2595

Closed
1 of 2 tasks
adamofig opened this issue Nov 15, 2020 · 1 comment · Fixed by #2821
Closed
1 of 2 tasks

Toast Ref OnClose, OnClick #2595

adamofig opened this issue Nov 15, 2020 · 1 comment · Fixed by #2821
Assignees

Comments

@adamofig
Copy link

I'm submitting a ... (check one with "x")

  • bug report
  • feature request

Issue description

Current behavior:

Toast events are not available as in other components like dialogs, methods like onClick() or onClose()

Expected behavior:

Should add onClose or onClick subscribe events to Toast reference

@aleksey-the-kid
Copy link

aleksey-the-kid commented Jun 2, 2021

If somebody will ever come across this issue and it will be still not resolved, there's actually a hack to make it work

On click:

const toastRef = NbToastrService.show(...)
((<any>toastRef)['toastContainer']).nativeElement.addEventListener('click', () => {
  // do stuff here
})

It works because toastRef has container, but it is private, so we trick ts compiler with any and access that field. In the container we have nativeElement which is just HTMLElement and we can do with it anything that js can do, add listeners, get styles, etc

On close is trickier but something like this should work:

const toastRef = ((<any>NbToastrService.show(...))['toastContainer']).nativeElement
const options = {
    root: toastRef,
    rootMargin: '0px',
    threshold: 0
}

const observer = new IntersectionObserver(onCloseHandler, options);

Something like that. Maybe you can even prepare some wrapper around NbToastRef to make a better architecture and make this hack isolated and reusable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants