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

Commit 2df6cff

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

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
@@ -248,19 +248,21 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
248248
}
249249
}
250250

251-
if (!hasClick && !proxies.length) {
252-
firstChild && firstChild.addEventListener('keypress', function(e) {
253-
if (e.target.nodeName != 'INPUT' && e.target.nodeName != 'TEXTAREA' && !e.target.isContentEditable) {
254-
var keyCode = e.which || e.keyCode;
255-
if (keyCode == $mdConstant.KEY_CODE.SPACE) {
256-
if (firstChild) {
257-
firstChild.click();
258-
e.preventDefault();
259-
e.stopPropagation();
260-
}
251+
var firstChildKeypressListener = function(e) {
252+
if (e.target.nodeName != 'INPUT' && e.target.nodeName != 'TEXTAREA' && !e.target.isContentEditable) {
253+
var keyCode = e.which || e.keyCode;
254+
if (keyCode == $mdConstant.KEY_CODE.SPACE) {
255+
if (firstChild) {
256+
firstChild.click();
257+
e.preventDefault();
258+
e.stopPropagation();
261259
}
262260
}
263-
});
261+
}
262+
};
263+
264+
if (!hasClick && !proxies.length) {
265+
firstChild && firstChild.addEventListener('keypress', firstChildKeypressListener);
264266
}
265267

266268
$element.off('click');
@@ -278,6 +280,10 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
278280
}
279281
});
280282
}
283+
284+
$scope.$on('$destroy', function () {
285+
firstChild && firstChild.removeEventListener('keypress', firstChildKeypressListener);
286+
});
281287
}
282288
}
283289
};

0 commit comments

Comments
 (0)