@@ -136,7 +136,13 @@ function mdListDirective($mdTheming) {
136
136
* </md-list-item>
137
137
* </hljs>
138
138
*
139
- * The `md-checkbox` element will be automatically detected as a proxy element and will toggle on click.
139
+ * The `md-checkbox` element will be automatically detected as a proxy element and will toggle on
140
+ * click.
141
+ *
142
+ * If not provided, an `aria-label` will be applied using the text of the list item.
143
+ * In this case, the following will be applied to the `md-checkbox`:
144
+ * `aria-label="Toggle First Line"`.
145
+ * When localizing your application, you should supply a localized `aria-label`.
140
146
*
141
147
* <hljs lang="html">
142
148
* <md-list-item>
@@ -220,12 +226,12 @@ function mdListDirective($mdTheming) {
220
226
* because otherwise some elements may not be clickable inside of the button.
221
227
*
222
228
* ---
223
- * When using a secondary item inside of your list item, the `md-list-item` component will automatically create
224
- * a secondary container at the end of the `md-list-item`, which contains all secondary items.
225
- *
226
- * The secondary item container is not static, because otherwise the overflow will not work properly on the
227
- * list item.
229
+ * When using a secondary item inside of your list item, the `md-list-item` component will
230
+ * automatically create a secondary container at the end of the `md-list-item`, which contains all
231
+ * secondary items.
228
232
*
233
+ * The secondary item container is not static, because that would cause issues with the overflow
234
+ * of the list item.
229
235
*/
230
236
function mdListItemDirective ( $mdAria , $mdConstant , $mdUtil , $timeout ) {
231
237
var proxiedTypes = [ 'md-checkbox' , 'md-switch' , 'md-menu' ] ;
@@ -260,7 +266,6 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
260
266
} else {
261
267
tElement . addClass ( 'md-no-proxy' ) ;
262
268
}
263
-
264
269
}
265
270
266
271
wrapSecondaryItems ( ) ;
@@ -278,9 +283,12 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
278
283
toggle = tElement . find ( toggleTypes [ i ] ) [ 0 ] ;
279
284
if ( toggle ) {
280
285
if ( ! toggle . hasAttribute ( 'aria-label' ) ) {
281
- var p = tElement . find ( 'p' ) [ 0 ] ;
282
- if ( ! p ) return ;
283
- toggle . setAttribute ( 'aria-label' , 'Toggle ' + p . textContent ) ;
286
+ var labelElement = tElement . find ( 'p' ) [ 0 ] ;
287
+ if ( ! labelElement ) {
288
+ labelElement = tElement . find ( 'span' ) [ 0 ] ;
289
+ }
290
+ if ( ! labelElement ) return ;
291
+ toggle . setAttribute ( 'aria-label' , 'Toggle ' + labelElement . textContent ) ;
284
292
}
285
293
}
286
294
}
@@ -326,8 +334,8 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
326
334
} else {
327
335
// Element which holds the default list-item content.
328
336
itemContainer = angular . element (
329
- '<div class="md-button md-no-style">' +
330
- ' <div class="md-list-item-inner"></div>' +
337
+ '<div class="md-button md-no-style">' +
338
+ ' <div class="md-list-item-inner"></div>' +
331
339
'</div>'
332
340
) ;
333
341
@@ -372,6 +380,10 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
372
380
itemContainer . append ( secondaryItemsWrapper ) ;
373
381
}
374
382
383
+ /**
384
+ * @param {HTMLElement } secondaryItem
385
+ * @param container
386
+ */
375
387
function wrapSecondaryItem ( secondaryItem , container ) {
376
388
// If the current secondary item is not a button, but contains a ng-click attribute,
377
389
// the secondary item will be automatically wrapped inside of a button.
@@ -391,9 +403,11 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
391
403
secondaryItem = buttonWrapper [ 0 ] ;
392
404
}
393
405
394
- if ( secondaryItem && ( ! hasClickEvent ( secondaryItem ) || ( ! tAttrs . ngClick && isProxiedElement ( secondaryItem ) ) ) ) {
395
- // In this case we remove the secondary class, so we can identify it later, when we searching for the
396
- // proxy items.
406
+ if ( secondaryItem &&
407
+ ( ! hasClickEvent ( secondaryItem ) ||
408
+ ( ! tAttrs . ngClick && isProxiedElement ( secondaryItem ) ) ) ) {
409
+ // In this case we remove the secondary class, so we can identify it later, when searching
410
+ // for the proxy items.
397
411
angular . element ( secondaryItem ) . removeClass ( 'md-secondary' ) ;
398
412
}
399
413
@@ -427,17 +441,29 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
427
441
} ) ;
428
442
}
429
443
430
- function isProxiedElement ( el ) {
431
- return proxiedTypes . indexOf ( el . nodeName . toLowerCase ( ) ) !== - 1 ;
444
+ /**
445
+ * @param {HTMLElement } element
446
+ * @return {boolean } true if the element has one of the proxied tags, false otherwise
447
+ */
448
+ function isProxiedElement ( element ) {
449
+ return proxiedTypes . indexOf ( element . nodeName . toLowerCase ( ) ) !== - 1 ;
432
450
}
433
451
434
- function isButton ( el ) {
435
- var nodeName = el . nodeName . toUpperCase ( ) ;
452
+ /**
453
+ * @param {HTMLElement } element
454
+ * @return {boolean } true if the element is a button or md-button, false otherwise
455
+ */
456
+ function isButton ( element ) {
457
+ var nodeName = element . nodeName . toUpperCase ( ) ;
436
458
437
459
return nodeName === "MD-BUTTON" || nodeName === "BUTTON" ;
438
460
}
439
461
440
- function hasClickEvent ( element ) {
462
+ /**
463
+ * @param {Element } element
464
+ * @return {boolean } true if the element has an ng-click attribute, false otherwise
465
+ */
466
+ function hasClickEvent ( element ) {
441
467
var attr = element . attributes ;
442
468
for ( var i = 0 ; i < attr . length ; i ++ ) {
443
469
if ( tAttrs . $normalize ( attr [ i ] . name ) === 'ngClick' ) return true ;
@@ -467,7 +493,7 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
467
493
$scope . mouseActive = false ;
468
494
proxy . on ( 'mousedown' , function ( ) {
469
495
$scope . mouseActive = true ;
470
- $timeout ( function ( ) {
496
+ $timeout ( function ( ) {
471
497
$scope . mouseActive = false ;
472
498
} , 100 ) ;
473
499
} )
@@ -481,20 +507,16 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
481
507
} ) ;
482
508
}
483
509
484
-
485
510
function computeProxies ( ) {
486
-
487
511
if ( firstElement && firstElement . children && ! hasClick && ! noProxies ) {
488
512
489
513
angular . forEach ( proxiedTypes , function ( type ) {
490
-
491
- // All elements which are not capable for being used a proxy have the .md-secondary class
492
- // applied. These items had been sorted out in the secondary wrap function.
514
+ // All elements which are not capable of being used as a proxy have the .md-secondary
515
+ // class applied. These items were identified in the secondary wrap function.
493
516
angular . forEach ( firstElement . querySelectorAll ( type + ':not(.md-secondary)' ) , function ( child ) {
494
517
proxies . push ( child ) ;
495
518
} ) ;
496
519
} ) ;
497
-
498
520
}
499
521
}
500
522
@@ -586,7 +608,6 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
586
608
* @ngdoc controller
587
609
* @name MdListController
588
610
* @module material.components.list
589
- *
590
611
*/
591
612
function MdListController ( $scope , $element , $mdListInkRipple ) {
592
613
var ctrl = this ;
0 commit comments