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

Commit b2afa36

Browse files
EladBezalelThomasBurleson
authored andcommitted
fix(list): removed keypress event listener from first child on destroy
fixes #5842 Closes #7057
1 parent abde470 commit b2afa36

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/components/list/list.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -288,19 +288,21 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
288288
}
289289
}
290290

291-
if (!hasClick && !proxies.length) {
292-
firstChild && firstChild.addEventListener('keypress', function(e) {
293-
if (e.target.nodeName != 'INPUT' && e.target.nodeName != 'TEXTAREA' && !e.target.isContentEditable) {
294-
var keyCode = e.which || e.keyCode;
295-
if (keyCode == $mdConstant.KEY_CODE.SPACE) {
296-
if (firstChild) {
297-
firstChild.click();
298-
e.preventDefault();
299-
e.stopPropagation();
300-
}
291+
var firstChildKeypressListener = function(e) {
292+
if (e.target.nodeName != 'INPUT' && e.target.nodeName != 'TEXTAREA' && !e.target.isContentEditable) {
293+
var keyCode = e.which || e.keyCode;
294+
if (keyCode == $mdConstant.KEY_CODE.SPACE) {
295+
if (firstChild) {
296+
firstChild.click();
297+
e.preventDefault();
298+
e.stopPropagation();
301299
}
302300
}
303-
});
301+
}
302+
};
303+
304+
if (!hasClick && !proxies.length) {
305+
firstChild && firstChild.addEventListener('keypress', firstChildKeypressListener);
304306
}
305307

306308
$element.off('click');
@@ -318,6 +320,10 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
318320
}
319321
});
320322
}
323+
324+
$scope.$on('$destroy', function () {
325+
firstChild && firstChild.removeEventListener('keypress', firstChildKeypressListener);
326+
});
321327
}
322328
}
323329
};

0 commit comments

Comments
 (0)