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

Commit f66e471

Browse files
author
Robert Messerle
committed
fix(list): prevents error when there are no child elements
1 parent fcbd2da commit f66e471

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/components/list/list.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ function mdListItemDirective($mdAria, $mdConstant, $timeout) {
157157

158158
function postLink($scope, $element, $attr, ctrl) {
159159

160-
var proxies = [];
160+
var proxies = [],
161+
firstChild = $element[0].firstElementChild,
162+
hasClick = firstChild && firstChild.hasAttribute('ng-click');
161163

162164
computeProxies();
163165
computeClickable();
@@ -187,25 +189,25 @@ function mdListItemDirective($mdAria, $mdConstant, $timeout) {
187189
var children = $element.children();
188190
if (children.length && !children[0].hasAttribute('ng-click')) {
189191
angular.forEach(proxiedTypes, function(type) {
190-
angular.forEach($element[0].firstElementChild.querySelectorAll(type), function(child) {
192+
angular.forEach(firstChild.querySelectorAll(type), function(child) {
191193
proxies.push(child);
192194
});
193195
});
194196
}
195197
}
196198
function computeClickable() {
197-
if (proxies.length || $element[0].firstElementChild.hasAttribute('ng-click')) {
199+
if (proxies.length || hasClick) {
198200
$element.addClass('md-clickable');
199201

200202
ctrl.attachRipple($scope, angular.element($element[0].querySelector('.md-no-style')));
201203
}
202204
}
203205

204-
if (!$element[0].firstElementChild.hasAttribute('ng-click') && !proxies.length) {
205-
$element[0].firstElementChild.addEventListener('keypress', function(e) {
206+
if (!hasClick && !proxies.length) {
207+
firstChild.addEventListener('keypress', function(e) {
206208
if (e.target.nodeName != 'INPUT') {
207209
if (e.keyCode == $mdConstant.KEY_CODE.SPACE) {
208-
$element[0].firstElementChild.click();
210+
firstChild.click();
209211
e.preventDefault();
210212
e.stopPropagation();
211213
}
@@ -216,9 +218,9 @@ function mdListItemDirective($mdAria, $mdConstant, $timeout) {
216218
$element.off('click');
217219
$element.off('keypress');
218220

219-
if (proxies.length) {
221+
if (proxies.length && firstChild) {
220222
$element.children().eq(0).on('click', function(e) {
221-
if ($element[0].firstElementChild.contains(e.target)) {
223+
if (firstChild.contains(e.target)) {
222224
angular.forEach(proxies, function(proxy) {
223225
if (e.target !== proxy && !proxy.contains(e.target)) {
224226
angular.element(proxy).triggerHandler('click');

0 commit comments

Comments
 (0)