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

Commit 5218c18

Browse files
topherfangioThomasBurleson
authored andcommitted
fix(divider): Fix stlying for md-divider inside md-list-item.
When an `md-divider` was used inside of a `md-list-item` with an `<md-button>`, the divider would improperly show up at the bottom of the list, instead of the bottom of each list item. Fix by making the list item's position relative. Also, we automatically apply special styling when we detect an `<md-button>` inside of the list item because we assume that it wraps all of the elements. If you simply wanted to use a secondary `<md-button>` or other clickable button inside a list, we would incorrectly apply this styling. Fix by automatically excluding `md-secondary` buttons and providing an additional `md-exclude` class that can be added to buttons. Fixes #3021. Closes #5058.
1 parent 57bd0c6 commit 5218c18

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

src/components/divider/demoBasicUsage/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ <h3>{{item.what}}</h3>
1414
<h4>{{item.who}}</h4>
1515
<p>{{item.notes}}</p>
1616
</div>
17+
<md-button class="md-secondary">Respond</md-button>
1718
<md-divider ng-if="!$last"></md-divider>
1819
</md-list-item>
1920
</md-list>

src/components/list/list.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ function mdListDirective($mdTheming) {
7575
* </md-list>
7676
* </hljs>
7777
*
78+
* _**Note:** We automatically apply special styling when the inner contents are wrapped inside
79+
* of a `<md-button>` tag. This styling is automatically ignored for `class="md-secondary"` buttons
80+
* and you can include a class of `class="md-exclude"` if you need to use a non-secondary button
81+
* that is inside the list, but does not wrap the contents._
7882
*/
7983
function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
8084
var proxiedTypes = ['md-checkbox', 'md-switch'];
@@ -98,7 +102,7 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
98102
}
99103
if (hasProxiedElement) {
100104
wrapIn('div');
101-
} else if (!tEl[0].querySelector('md-button')) {
105+
} else if (!tEl[0].querySelector('md-button:not(.md-secondary):not(.md-exclude)')) {
102106
tEl.addClass('md-no-proxy');
103107
}
104108
} else {

src/components/list/list.scss

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ md-list {
3939
}
4040

4141
md-list-item {
42+
// Ensure nested dividers are properly positioned
43+
position: relative;
44+
4245
&.md-proxy-focus.md-focused .md-no-style {
4346
transition: background-color 0.15s linear;
4447
}

src/components/list/list.spec.js

+11
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,15 @@ describe('mdListItem directive', function() {
132132
expect(listItem.hasClass('md-no-proxy')).toBeFalsy();
133133
});
134134

135+
it('should not detect secondary or excluded md-buttons', function() {
136+
var listItem = setup(
137+
'<md-list-item>' +
138+
' <div>Content Here</div>' +
139+
' <md-button class="md-secondary" ng-click="sayHello()">Hello</md-button>' +
140+
' <md-button class="md-exclude" ng-click="sayHello()">Hello</md-button>' +
141+
'</md-list-item>'
142+
);
143+
expect(listItem.hasClass('md-no-proxy')).toBeTruthy();
144+
});
145+
135146
});

0 commit comments

Comments
 (0)