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

Commit 8fd6daf

Browse files
Splaktarandrewseguin
authored andcommitted
fix(toast): do not auto set any actionKeys (#11510)
provide warning if an action is defined without an actionKey fix custom toast example to call removeActionKeyListener() Fixes #11474
1 parent ca10bd0 commit 8fd6daf

File tree

3 files changed

+305
-291
lines changed

3 files changed

+305
-291
lines changed

src/components/toast/demoCustomUsage/script.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
};
3535
}
3636

37-
function ToastCtrl($mdToast, $mdDialog, $document) {
37+
function ToastCtrl($mdToast, $mdDialog, $document, $scope) {
3838
var ctrl = this;
3939
ctrl.keyListenerConfigured = false;
4040
ctrl.undoKey = UNDO_KEY;
@@ -70,7 +70,7 @@
7070
};
7171

7272
/**
73-
* @param {KeyboardEvent} event
73+
* @param {KeyboardEvent} event to handle
7474
*/
7575
function handleKeyDown(event) {
7676
if (event.key === 'Escape') {
@@ -92,9 +92,14 @@
9292
}
9393

9494
function removeActionKeyListener() {
95-
$document.off('keydown');
96-
ctrl.keyListenerConfigured = false;
95+
if (ctrl.keyListenerConfigured) {
96+
$document.off('keydown');
97+
ctrl.keyListenerConfigured = false;
98+
}
9799
}
98-
}
99100

101+
$scope.$on('$destroy', function() {
102+
removeActionKeyListener();
103+
});
104+
}
100105
})();

0 commit comments

Comments
 (0)