JosephusPaye / Keen-UI

A lightweight Vue.js UI library with a simple API, inspired by Google's Material Design.
https://josephuspaye.github.io/Keen-UI/
MIT License
4.1k stars 438 forks source link

How to dismiss a UiSnackbarContainer? #493

Closed sysebert closed 4 years ago

sysebert commented 4 years ago

I'm looking for a way to dismiss a snackbar using the UiSnackbarContainer. Ideally it'd work the exact same way as hideOnClick does, but be able to do that via a method on the container.

I want to have an action that says "close" trigger the method in the onActionClick handler.

Any tips or tricks would be appreciated!

this.$refs.snackbarContainer.createSnackbar({
  action: 'Close',
  actionColor: 'primary',
  duration: 8000,
  message: 'Some message',
  onActionClick: () => {
    // not sure what to put here to make it hide
  },
});
JosephusPaye commented 4 years ago

The onActionClick hook actually receives the snackbar as an argument (reference).

So you can do:

this.$refs.snackbarContainer.createSnackbar({
  message: 'Some message',
  action: 'Close',
  onActionClick: (snackbar) => {
    snackbar.show = false; // Hide the snackbar
  },
});

~This needs to be documented.~ Update: it actually is documented with the createSnackbar() method 😅.

sysebert commented 4 years ago

I'm not sure where in the docs you mean, but this is the page I basically leave in my tabs: https://josephuspaye.github.io/Keen-UI/#/ui-snackbar :)

But, thanks, this is perfect!