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

Commit bb5c105

Browse files
devversionThomasBurleson
authored andcommitted
fix(list): show item content separated to the button
Fixes #6984. Fixes #6488. Closes #6493.
1 parent ad9ba52 commit bb5c105

File tree

4 files changed

+70
-20
lines changed

4 files changed

+70
-20
lines changed

src/components/button/button.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ angular
2525
* the `md-primary` class.
2626
*
2727
* @param {boolean=} md-no-ink If present, disable ripple ink effects.
28+
* @param {boolean=} md-no-focus-style If present, disable focus style on button
2829
* @param {expression=} ng-disabled En/Disable based on the expression
2930
* @param {string=} md-ripple-size Overrides the default ripple size logic. Options: `full`, `partial`, `auto`
3031
* @param {string=} aria-label Adds alternative text to button for accessibility, useful for icon buttons.
@@ -108,9 +109,10 @@ function MdButtonDirective($mdButtonInkRipple, $mdTheming, $mdAria, $timeout) {
108109
}
109110
});
110111

111-
// restrict focus styles to the keyboard
112-
scope.mouseActive = false;
113-
element.on('mousedown', function() {
112+
if (!angular.isDefined(attr.mdNoFocusStyle)) {
113+
// restrict focus styles to the keyboard
114+
scope.mouseActive = false;
115+
element.on('mousedown', function() {
114116
scope.mouseActive = true;
115117
$timeout(function(){
116118
scope.mouseActive = false;
@@ -124,6 +126,7 @@ function MdButtonDirective($mdButtonInkRipple, $mdTheming, $mdAria, $timeout) {
124126
.on('blur', function(ev) {
125127
element.removeClass('md-focused');
126128
});
129+
}
127130
}
128131

129132
}

src/components/list/list.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,19 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
136136
container.append(tEl.contents());
137137
tEl.addClass('md-proxy-focus');
138138
} else {
139-
container = angular.element('<md-button class="md-no-style"><div class="md-list-item-inner"></div></md-button>');
140-
copyAttributes(tEl[0], container[0]);
141-
container.children().eq(0).append(tEl.contents());
139+
// Element which holds the default list-item content.
140+
container = angular.element('<div class="md-button md-no-style"><div class="md-list-item-inner"></div></div>');
141+
142+
// Button which shows ripple and executes primary action.
143+
var buttonWrap = angular.element('<md-button class="md-no-style" md-no-focus-style></md-button>');
144+
buttonWrap[0].setAttribute('aria-label', tEl[0].textContent);
145+
copyAttributes(tEl[0], buttonWrap[0]);
146+
147+
// Append the button wrap before our list-item content, because it will overlay in relative.
148+
container.prepend(buttonWrap);
149+
container.children().eq(1).append(tEl.contents());
150+
151+
tEl.addClass('md-button-wrap');
142152
}
143153

144154
tEl[0].setAttribute('tabindex', '-1');
@@ -179,7 +189,11 @@ function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
179189
( tAttrs.ngClick &&
180190
isProxiedElement(secondaryItem) )
181191
)) {
182-
secondaryItem.classList.remove('md-secondary');
192+
// When using multiple secondary items we need to remove their secondary class to be
193+
// orderd correctly in the list-item
194+
if (hasSecondaryItemsWrapper) {
195+
secondaryItem.classList.remove('md-secondary');
196+
}
183197
tEl.addClass('md-with-secondary');
184198
container.append(secondaryItem);
185199
}

src/components/list/list.scss

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,33 @@ md-list-item {
4545
&.md-proxy-focus.md-focused .md-no-style {
4646
transition: background-color 0.15s linear;
4747
}
48+
49+
&.md-button-wrap {
50+
position: relative;
51+
52+
> .md-button:first-child {
53+
padding: 0;
54+
margin: 0;
55+
font-weight: 400;
56+
background-color: inherit;
57+
text-align: left;
58+
border: medium none;
59+
60+
> .md-button:first-child {
61+
height: 100%;
62+
position: absolute;
63+
margin: 0;
64+
padding: 0;
65+
}
66+
67+
.md-list-item-inner {
68+
padding: 0 16px;
69+
}
70+
71+
}
72+
73+
}
74+
4875
&.md-no-proxy,
4976
.md-no-style {
5077
position: relative;

src/components/list/list.spec.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,49 +104,55 @@ describe('mdListItem directive', function() {
104104

105105
it('creates buttons when used with ng-click', function() {
106106
var listItem = setup('<md-list-item ng-click="sayHello()" ng-disabled="true"><p>Hello world</p></md-list-item>');
107-
var firstChild = listItem.children()[0];
108-
expect(firstChild.nodeName).toBe('MD-BUTTON');
109-
expect(firstChild.hasAttribute('ng-disabled')).toBeTruthy();
110-
expect(firstChild.childNodes[0].nodeName).toBe('DIV');
111-
expect(firstChild.childNodes[0].childNodes[0].nodeName).toBe('P');
107+
var buttonChild = listItem.children().children()[0];
108+
var innerChild = listItem.children().children()[1];
109+
expect(buttonChild.nodeName).toBe('MD-BUTTON');
110+
expect(buttonChild.hasAttribute('ng-disabled')).toBeTruthy();
111+
expect(innerChild.nodeName).toBe('DIV');
112+
expect(innerChild.childNodes[0].nodeName).toBe('P');
112113
});
113114

114115
it('creates buttons when used with ui-sref', function() {
115116
var listItem = setup('<md-list-item ui-sref="somestate"><p>Hello world</p></md-list-item>');
116-
var firstChild = listItem.children()[0];
117+
var firstChild = listItem.children().children()[0];
117118
expect(firstChild.nodeName).toBe('MD-BUTTON');
118119
expect(firstChild.hasAttribute('ui-sref')).toBeTruthy();
119120
});
120121

121122
it('creates buttons when used with href', function() {
122123
var listItem = setup('<md-list-item href="/somewhere"><p>Hello world</p></md-list-item>');
123-
var firstChild = listItem.children()[0];
124+
var firstChild = listItem.children().children()[0];
124125
expect(firstChild.nodeName).toBe('MD-BUTTON');
125126
expect(firstChild.hasAttribute('href')).toBeTruthy();
126127
});
127128

128129
it('moves aria-label to primary action', function() {
129130
var listItem = setup('<md-list-item ng-click="sayHello()" aria-label="Hello"></md-list-item>');
130131
var listItemChildren = listItem.children();
131-
expect(listItemChildren[0].nodeName).toBe('MD-BUTTON');
132-
expect(listItemChildren.attr('aria-label')).toBe('Hello');
132+
expect(listItemChildren[0].nodeName).toBe('DIV');
133+
expect(listItemChildren).toHaveClass('md-button');
134+
expect(listItemChildren.children()[0].getAttribute('aria-label')).toBe('Hello');
133135
});
134136

135137
it('moves md-secondary items outside of the button', function() {
136138
var listItem = setup('<md-list-item ng-click="sayHello()"><p>Hello World</p><md-icon class="md-secondary" ng-click="goWild()"></md-icon></md-list-item>');
139+
// First child is our button and content holder
137140
var firstChild = listItem.children().eq(0);
138-
expect(firstChild[0].nodeName).toBe('MD-BUTTON');
139-
expect(firstChild.children().length).toBe(1);
141+
expect(firstChild[0].nodeName).toBe('DIV');
142+
// It should contain two elements, the button overlay and the actual content
143+
expect(firstChild.children().length).toBe(2);
140144
var secondChild = listItem.children().eq(1);
141145
expect(secondChild[0].nodeName).toBe('MD-BUTTON');
142146
expect(secondChild.hasClass('md-secondary-container')).toBeTruthy();
143147
});
144148

145149
it('moves multiple md-secondary items outside of the button', function() {
146150
var listItem = setup('<md-list-item ng-click="sayHello()"><p>Hello World</p><md-icon class="md-secondary" ng-click="goWild()"><md-icon class="md-secondary" ng-click="goWild2()"></md-icon></md-list-item>');
151+
// First child is our button and content holder
147152
var firstChild = listItem.children().eq(0);
148-
expect(firstChild[0].nodeName).toBe('MD-BUTTON');
149-
expect(firstChild.children().length).toBe(1);
153+
expect(firstChild[0].nodeName).toBe('DIV');
154+
// It should contain two elements, the button overlay and the actual content
155+
expect(firstChild.children().length).toBe(2);
150156
var secondChild = listItem.children().eq(1);
151157
expect(secondChild[0].nodeName).toBe('DIV');
152158
expect(secondChild.hasClass('md-secondary-container')).toBeTruthy();

0 commit comments

Comments
 (0)