diff --git a/src/components/list/list.js b/src/components/list/list.js
index 6379ee9fa03..47ea10e6c78 100644
--- a/src/components/list/list.js
+++ b/src/components/list/list.js
@@ -136,14 +136,7 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
tEl.addClass('md-proxy-focus');
} else {
container = angular.element('');
- var copiedAttrs = ['ng-click', 'aria-label', 'ng-disabled',
- 'ui-sref', 'href', 'ng-href', 'ng-attr-ui-sref'];
- angular.forEach(copiedAttrs, function(attr) {
- if (tEl[0].hasAttribute(attr)) {
- container[0].setAttribute(attr, tEl[0].getAttribute(attr));
- tEl[0].removeAttribute(attr);
- }
- });
+ copyAttributes(tEl[0], container[0]);
container.children().eq(0).append(tEl.contents());
}
@@ -153,8 +146,7 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
if (secondaryItem && !isButton(secondaryItem) && secondaryItem.hasAttribute('ng-click')) {
$mdAria.expect(secondaryItem, 'aria-label');
var buttonWrapper = angular.element('');
- buttonWrapper.attr('ng-click', secondaryItem.getAttribute('ng-click'));
- secondaryItem.removeAttribute('ng-click');
+ copyAttributes(secondaryItem, buttonWrapper[0]);
secondaryItem.setAttribute('tabindex', '-1');
secondaryItem.classList.remove('md-secondary');
buttonWrapper.append(secondaryItem);
@@ -172,6 +164,17 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
}
}
+ function copyAttributes(item, wrapper) {
+ var copiedAttrs = ['ng-click', 'aria-label', 'ng-disabled',
+ 'ui-sref', 'href', 'ng-href', 'ng-attr-ui-sref'];
+ angular.forEach(copiedAttrs, function(attr) {
+ if (item.hasAttribute(attr)) {
+ wrapper.setAttribute(attr, item.getAttribute(attr));
+ item.removeAttribute(attr);
+ }
+ });
+ }
+
function isProxiedElement(el) {
return proxiedTypes.indexOf(el.nodeName.toLowerCase()) != -1;
}
diff --git a/src/components/list/list.spec.js b/src/components/list/list.spec.js
index 9ef46fe62cb..384c26b41e8 100644
--- a/src/components/list/list.spec.js
+++ b/src/components/list/list.spec.js
@@ -3,7 +3,7 @@ describe('mdListItem directive', function() {
var $compile, $rootScope;
beforeEach(module('material.components.list', 'material.components.checkbox', 'material.components.switch'));
- beforeEach(inject(function(_$compile_, _$rootScope_){
+ beforeEach(inject(function(_$compile_, _$rootScope_) {
$compile = _$compile_;
$rootScope = _$rootScope_;
}));
@@ -26,16 +26,16 @@ describe('mdListItem directive', function() {
return el;
}
- it('supports empty list items',function() {
+ it('supports empty list items', function() {
var list = setup('\
\
\
'
- );
+ );
var cntr = list[0].querySelector('div');
- if (cntr && cntr.click ) {
+ if (cntr && cntr.click) {
cntr.click();
expect($rootScope.modelVal).toBe(false);
}
@@ -46,7 +46,7 @@ describe('mdListItem directive', function() {
var listItem = setup('');
var cntr = listItem[0].querySelector('div');
- if (cntr && cntr.click ) {
+ if (cntr && cntr.click) {
cntr.click();
expect($rootScope.modelVal).toBe(true);
}
@@ -57,7 +57,7 @@ describe('mdListItem directive', function() {
var listItem = setup('');
var cntr = listItem[0].querySelector('div');
- if (cntr && cntr.click ) {
+ if (cntr && cntr.click) {
cntr.click();
expect($rootScope.modelVal).toBe(true);
}
@@ -65,40 +65,40 @@ describe('mdListItem directive', function() {
});
it('should convert spacebar keypress events as clicks', inject(function($mdConstant) {
- var listItem = setup('');
- var checkbox = angular.element(listItem[0].querySelector('md-checkbox'));
-
- expect($rootScope.modelVal).toBeFalsy();
- checkbox.triggerHandler({
- type: 'keypress',
- keyCode: $mdConstant.KEY_CODE.SPACE
- });
- expect($rootScope.modelVal).toBe(true);
+ var listItem = setup('');
+ var checkbox = angular.element(listItem[0].querySelector('md-checkbox'));
+
+ expect($rootScope.modelVal).toBeFalsy();
+ checkbox.triggerHandler({
+ type: 'keypress',
+ keyCode: $mdConstant.KEY_CODE.SPACE
+ });
+ expect($rootScope.modelVal).toBe(true);
}));
it('should not convert spacebar keypress for text areas', inject(function($mdConstant) {
- var listItem = setup('');
- var inputEl = angular.element(listItem[0].querySelector('textarea')[0]);
-
- expect($rootScope.modelVal).toBeFalsy();
- inputEl.triggerHandler({
- type: 'keypress',
- keyCode: $mdConstant.KEY_CODE.SPACE
- });
- expect($rootScope.modelVal).toBeFalsy();
+ var listItem = setup('');
+ var inputEl = angular.element(listItem[0].querySelector('textarea')[0]);
+
+ expect($rootScope.modelVal).toBeFalsy();
+ inputEl.triggerHandler({
+ type: 'keypress',
+ keyCode: $mdConstant.KEY_CODE.SPACE
+ });
+ expect($rootScope.modelVal).toBeFalsy();
}));
xit('should not convert spacebar keypress for text inputs', inject(function($mdConstant) {
- var listItem = setup('');
- var inputEl = angular.element(listItem[0].querySelector('input')[0]);
+ var listItem = setup('');
+ var inputEl = angular.element(listItem[0].querySelector('input')[0]);
- expect($rootScope.pressed).toBeFalsy();
- inputEl.triggerHandler({
- type: 'keypress',
- keyCode: $mdConstant.KEY_CODE.SPACE
- });
- expect($rootScope.pressed).toBe(true);
+ expect($rootScope.pressed).toBeFalsy();
+ inputEl.triggerHandler({
+ type: 'keypress',
+ keyCode: $mdConstant.KEY_CODE.SPACE
+ });
+ expect($rootScope.pressed).toBe(true);
}));
@@ -157,6 +157,21 @@ describe('mdListItem directive', function() {
expect(listItem.hasClass('md-no-proxy')).toBeTruthy();
});
+ it('should copy md-icon.md-secondary attributes to the button', function() {
+ var listItem = setup(
+ '' +
+ ' Content Here
' +
+ ' ' +
+ ' Hello' +
+ ''
+ );
+
+ var button = listItem.find('md-button');
+
+ expect(button[0].hasAttribute('ng-click')).toBeTruthy();
+ expect(button[0].hasAttribute('ng-disabled')).toBeTruthy();
+ });
+
describe('with a clickable item', function() {
it('should wrap secondary icons in a md-button', function() {