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

Commit f8a8b3c

Browse files
committed
fix(list): restore ui-sref and href support on md-list-item
closes #2131
1 parent f966d0f commit f8a8b3c

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/components/list/list.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
9393

9494
tEl[0].setAttribute('role', 'listitem');
9595

96-
if (!tAttrs.ngClick) {
96+
if (tAttrs.ngClick || tAttrs.ngHref || tAttrs.href || tAttrs.uiSref || tAttrs.ngAttrUiSref) {
97+
wrapIn('button');
98+
} else {
9799
for (var i = 0, type; type = proxiedTypes[i]; ++i) {
98100
if (proxyElement = tEl[0].querySelector(type)) {
99101
hasProxiedElement = true;
@@ -105,8 +107,6 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
105107
} else if (!tEl[0].querySelector('md-button:not(.md-secondary):not(.md-exclude)')) {
106108
tEl.addClass('md-no-proxy');
107109
}
108-
} else {
109-
wrapIn('button');
110110
}
111111
setupToggleAria();
112112

@@ -134,7 +134,8 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
134134
tEl.addClass('md-proxy-focus');
135135
} else {
136136
container = angular.element('<md-button class="md-no-style"><div class="md-list-item-inner"></div></md-button>');
137-
var copiedAttrs = ['ng-click', 'aria-label', 'ng-disabled'];
137+
var copiedAttrs = ['ng-click', 'aria-label', 'ng-disabled',
138+
'ui-sref', 'href', 'ng-href', 'ng-attr-ui-sref'];
138139
angular.forEach(copiedAttrs, function(attr) {
139140
if (tEl[0].hasAttribute(attr)) {
140141
container[0].setAttribute(attr, tEl[0].getAttribute(attr));

src/components/list/list.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,20 @@ describe('mdListItem directive', function() {
111111
expect(firstChild.childNodes[0].childNodes[0].nodeName).toBe('P');
112112
});
113113

114+
it('creates buttons when used with ui-sref', function() {
115+
var listItem = setup('<md-list-item ui-sref="somestate"><p>Hello world</p></md-list-item>');
116+
var firstChild = listItem.children()[0];
117+
expect(firstChild.nodeName).toBe('MD-BUTTON');
118+
expect(firstChild.hasAttribute('ui-sref')).toBeTruthy();
119+
});
120+
121+
it('creates buttons when used with href', function() {
122+
var listItem = setup('<md-list-item href="/somewhere"><p>Hello world</p></md-list-item>');
123+
var firstChild = listItem.children()[0];
124+
expect(firstChild.nodeName).toBe('MD-BUTTON');
125+
expect(firstChild.hasAttribute('href')).toBeTruthy();
126+
});
127+
114128
it('moves aria-label to primary action', function() {
115129
var listItem = setup('<md-list-item ng-click="sayHello()" aria-label="Hello"></md-list-item>');
116130
var listItemChildren = listItem.children();

0 commit comments

Comments
 (0)