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: add the "remove" method to close a specific toast message #4101

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions components/lib/toast/Toast.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default {
styleElement: null,
mounted() {
ToastEventBus.on('add', this.onAdd);
ToastEventBus.on('remove', this.onRemove);
ToastEventBus.on('remove-group', this.onRemoveGroup);
ToastEventBus.on('remove-all-groups', this.onRemoveAllGroups);

Expand All @@ -58,6 +59,7 @@ export default {
}

ToastEventBus.off('add', this.onAdd);
ToastEventBus.off('remove', this.onRemove);
ToastEventBus.off('remove-group', this.onRemoveGroup);
ToastEventBus.off('remove-all-groups', this.onRemoveAllGroups);
},
Expand Down Expand Up @@ -87,6 +89,9 @@ export default {
this.add(message);
}
},
onRemove(message) {
this.remove({ message, type: 'close' });
},
onRemoveGroup(group) {
if (this.group === group) {
this.messages = [];
Expand Down
5 changes: 5 additions & 0 deletions components/lib/toastservice/ToastService.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export interface ToastServiceMethods {
* @param {ToastMessageOptions} message - Message instance.
*/
add(message: ToastMessageOptions): void;
/**
* Clears the message.
* @param {ToastMessageOptions} message - Message instance.
*/
remove(message: ToastMessageOptions): void;
/**
* Clears the messages that belongs to the group.
* @param {string} group - Name of the message group.
Expand Down
3 changes: 3 additions & 0 deletions components/lib/toastservice/ToastService.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export default {
add: (message) => {
ToastEventBus.emit('add', message);
},
remove: (message) => {
ToastEventBus.emit('remove', message);
},
removeGroup: (group) => {
ToastEventBus.emit('remove-group', group);
},
Expand Down
13 changes: 13 additions & 0 deletions doc/common/apidoc/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -39204,6 +39204,19 @@
"returnType": "void",
"description": "Displays the message in a suitable Toast component."
},
{
"name": "remove",
"parameters": [
{
"name": "message",
"optional": false,
"type": "ToastMessageOptions",
"description": "Message instance."
}
],
"returnType": "void",
"description": "Clears the message."
},
{
"name": "removeGroup",
"parameters": [
Expand Down