Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit e625a9c

Browse files
committed
fix(toast): onRemove doesn't return a Promise in some cases
- this results in an exception - add types for `$q` - improve JSDoc Fixes #10379
1 parent 546bd84 commit e625a9c

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"devDependencies": {
3535
"@octokit/rest": "^17.0.1",
3636
"@types/angular": "~1.6.57",
37+
"@types/q": "^1.5.4",
3738
"acorn": "^7.1.1",
3839
"add-stream": "^1.0.0",
3940
"ajv": "^6.12.0",

src/components/toast/toast.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ function MdToastProvider($$interimElementProvider) {
416416
}
417417

418418
/* @ngInject */
419-
function toastDefaultOptions($animate, $mdToast, $mdUtil, $mdMedia, $document) {
419+
function toastDefaultOptions($animate, $mdToast, $mdUtil, $mdMedia, $document, $q) {
420420
var SWIPE_EVENTS = '$md.swipeleft $md.swiperight $md.swipeup $md.swipedown';
421421
return {
422422
onShow: onShow,
@@ -518,6 +518,12 @@ function MdToastProvider($$interimElementProvider) {
518518
});
519519
}
520520

521+
/**
522+
* @param {object} scope the toast's scope
523+
* @param {JQLite} element the toast to be removed
524+
* @param {object} options
525+
* @return {Promise<*>} a Promise to remove the element immediately or to animate it out.
526+
*/
521527
function onRemove(scope, element, options) {
522528
if (scope.toast && scope.toast.actionKey) {
523529
removeActionKeyListener();
@@ -526,7 +532,8 @@ function MdToastProvider($$interimElementProvider) {
526532
if (options.parent) options.parent.addClass('md-toast-animating');
527533
if (options.openClass) options.parent.removeClass(options.openClass);
528534

529-
return ((options.$destroy === true) ? element.remove() : $animate.leave(element))
535+
// Don't run the leave animation if the element has already been destroyed.
536+
return ((options.$destroy === true) ? $q.when(element.remove()) : $animate.leave(element))
530537
.then(function () {
531538
if (options.parent) options.parent.removeClass('md-toast-animating');
532539
if ($mdUtil.hasComputedStyle(options.parent, 'position', 'static')) {

0 commit comments

Comments
 (0)