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

Allow hiding toastr via public method #1008

Closed
1 of 2 tasks
ilDon opened this issue Nov 21, 2018 · 1 comment · Fixed by #1058
Closed
1 of 2 tasks

Allow hiding toastr via public method #1008

ilDon opened this issue Nov 21, 2018 · 1 comment · Fixed by #1058
Assignees
Milestone

Comments

@ilDon
Copy link

ilDon commented Nov 21, 2018

Issue type

I'm submitting a ...

  • bug report
  • feature request

Issue description

Current behavior:
Toastr can't be closed programmatically via a method like hide()/close().

If we set duration to 0 and destroyByClick to false, there is no easy way to get rid of the toastr.

Expected behavior:
It would be handy to destroy the toastr via a method exposed by NbToastrService. In this way we could do something like:

this.toastrService.show(message, title, toastrConfig);

Related code:
My current workaround is the following.

In the component where I show the toastr that I want to delete programmatically, I set this in the constructor:

constructor(
  private toastrService: NbToastrService,
  private containerRegistry: NbToastrContainerRegistry
) { }

Then, to delete the toastr, I do the following

const container = this.containerRegistry.get(this.toastrConfig.position);
const index = container['toasts'].findIndex(toast => toast.message === this.message && toast.title === this.title);
if (index > -1)
  container['toasts'].splice(index, 1);

The method exposed by NbToastrService could work in a similar fashion. Alternatively, it would be easier to make show() return the toast object, and then we could use that to close it, like so:

const toast = this.toastrService.show(message, title, toastrConfig);
toastrService.close(toast);

PS In my workaround I use container['toasts'] instead of container.toasts to avoid error messages on toasts being a protected property.

@Tibing
Copy link
Member

Tibing commented Nov 30, 2018

Hi @ilDon, thanks for your feature request. If you want to help, please, feel free to submit pull requests 😄

@Tibing Tibing added the Backlog label Nov 30, 2018
@issue-sh issue-sh bot assigned Tibing Dec 6, 2018
@yggg yggg added this to the 3.1.0 milestone Dec 6, 2018
@issue-sh issue-sh bot added Sprint and removed Backlog labels Dec 6, 2018
@issue-sh issue-sh bot added Backlog and removed In Progress labels Dec 13, 2018
@issue-sh issue-sh bot removed the Sprint label Dec 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants