Skip to content

Commit 03120bb

Browse files
joaofndsGarbee
authored andcommitted
Add Snackbar hide method
1 parent fd21836 commit 03120bb

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/snackbar/snackbar.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
this.actionHandler_ = undefined;
3939
this.message_ = undefined;
4040
this.actionText_ = undefined;
41+
this.timeoutID_ = undefined;
4142
this.queuedNotifications_ = [];
4243
this.setActionHidden_(true);
4344
};
@@ -86,7 +87,7 @@
8687
this.textElement_.textContent = this.message_;
8788
this.element_.classList.add(this.cssClasses_.ACTIVE);
8889
this.element_.setAttribute('aria-hidden', 'false');
89-
setTimeout(this.cleanup_.bind(this), this.timeout_);
90+
this.timeoutID_ = setTimeout(this.cleanup_.bind(this), this.timeout_);
9091

9192
};
9293

@@ -127,7 +128,21 @@
127128
}
128129
};
129130
MaterialSnackbar.prototype['showSnackbar'] = MaterialSnackbar.prototype.showSnackbar;
130-
131+
/**
132+
* Hide the snackbar.
133+
*
134+
* @public
135+
*/
136+
MaterialSnackbar.prototype.hideSnackbar = function() {
137+
if (!this.active) {
138+
return;
139+
}
140+
if (typeof this.timeoutID_ === 'number') {
141+
clearTimeout(this.timeoutID_);
142+
this.cleanup_();
143+
}
144+
};
145+
MaterialSnackbar.prototype['hideSnackbar'] = MaterialSnackbar.prototype.hideSnackbar;
131146
/**
132147
* Check if the queue has items within it.
133148
* If it does, display the next entry.
@@ -158,6 +173,7 @@
158173
this.actionHandler_ = undefined;
159174
this.message_ = undefined;
160175
this.actionText_ = undefined;
176+
this.timeoutID_ = undefined;
161177
this.active = false;
162178
this.checkQueue_();
163179
}.bind(this), /** @type {number} */ (this.Constant_.ANIMATION_LENGTH));

0 commit comments

Comments
 (0)