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

Commit 5d9874f

Browse files
MagicIndustriesrschmukler
authored andcommitted
feat(select): BREAKING: allow md-input-container label and remove
md-select-label closes #2684, closes #1586, closes #3307 BREAKING: `md-select-label` is no longer uses. The select will now always display the selected value as the text in the `md-option`. This makes for a better UX for users, as otherwise it was possible to confuse them. `md-select` still supports using the `placeholder` attribute outside of an `md-input-container` but the preferred way of using `md-select` is now as follows: ```html <md-input-container> <label>State</label> <md-select ng-model="selectedState"> <md-option value="{{state}}" ng-repeat="state in states"> </md-select> </md-input-container> ```
1 parent 7fe482c commit 5d9874f

File tree

10 files changed

+270
-167
lines changed

10 files changed

+270
-167
lines changed

src/components/input/input.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ function inputTextareaDirective($mdUtil, $window, $mdAria) {
168168

169169
if ( !containerCtrl ) return;
170170
if (containerCtrl.input) {
171-
throw new Error("<md-input-container> can only have *one* <input> or <textarea> child element!");
171+
throw new Error("<md-input-container> can only have *one* <input>, <textarea> or <md-select> child element!");
172172
}
173173
containerCtrl.input = element;
174174

@@ -327,7 +327,6 @@ function mdMaxlengthDirective($animate) {
327327
}
328328

329329
function placeholderDirective($log) {
330-
var blackListElements = ['MD-SELECT'];
331330
return {
332331
restrict: 'A',
333332
require: '^^?mdInputContainer',
@@ -337,7 +336,6 @@ function placeholderDirective($log) {
337336

338337
function postLink(scope, element, attr, inputContainer) {
339338
if (!inputContainer) return;
340-
if (blackListElements.indexOf(element[0].nodeName) != -1) return;
341339
if (angular.isDefined(inputContainer.element.attr('md-no-float'))) return;
342340

343341
var placeholderText = attr.placeholder;
@@ -348,7 +346,7 @@ function placeholderDirective($log) {
348346

349347
inputContainer.element.addClass('md-icon-float');
350348
inputContainer.element.prepend(placeholder);
351-
} else {
349+
} else if (element[0].nodeName != 'MD-SELECT') {
352350
$log.warn("The placeholder='" + placeholderText + "' will be ignored since this md-input-container has a child label element.");
353351
}
354352

src/components/input/input.scss

+5-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ md-input-container {
8080

8181

8282
label:not(.md-no-float),
83-
.md-placeholder:not(.md-select-label) {
83+
.md-placeholder {
8484
order: 1;
8585
pointer-events: none;
8686
-webkit-font-smoothing: antialiased;
@@ -91,12 +91,15 @@ md-input-container {
9191

9292
@include rtl(transform-origin, left top, right top);
9393
}
94-
.md-placeholder:not(.md-select-label) {
94+
.md-placeholder {
9595
position: absolute;
9696
top: 0;
9797
opacity: 0;
9898
transition-property: opacity, transform;
9999
transform: translate3d(0, $input-placeholder-offset + $baseline-grid * 0.75, 0);
100+
&.md-static {
101+
position: static;
102+
}
100103
}
101104
&.md-input-focused .md-placeholder {
102105
opacity: 1;

src/components/select/demoBasicUsage/index.html

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ <h1 class="md-title">Enter an address</h1>
1010
<label>City</label>
1111
<input type="text"/>
1212
</md-input-container>
13-
<md-select placeholder="State" ng-model="ctrl.userState">
14-
<md-option ng-repeat="state in ctrl.states" value="{{state.abbrev}}">{{state.abbrev}}</md-option>
15-
</md-select>
13+
<md-input-container>
14+
<label>State</label>
15+
<md-select ng-model="ctrl.userState">
16+
<md-option ng-repeat="state in ctrl.states" value="{{state.abbrev}}">{{state.abbrev}}</md-option>
17+
</md-select>
18+
</md-input-container>
1619
</div>
1720
</div>
1821
</div>

src/components/select/demoOptionGroups/index.html

+17-11
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22
<div>
33
<h1 class="md-title">Pick your pizza below</h1>
44
<div layout="row">
5-
<md-select ng-model="size" placeholder="Size">
6-
<md-option ng-repeat="size in sizes" value="{{size}}">{{size}}</md-option>
7-
</md-select>
8-
<md-select ng-model="topping" placeholder="Topping">
9-
<md-optgroup label="Meats">
10-
<md-option ng-value="topping.name" ng-repeat="topping in toppings | filter: {category: 'meat' }">{{topping.name}}</md-option>
11-
</md-optgroup>
12-
<md-optgroup label="Veggies">
13-
<md-option ng-value="topping.name" ng-repeat="topping in toppings | filter: {category: 'veg' }">{{topping.name}}</md-option>
14-
</md-optgroup>
15-
</md-select>
5+
<md-input-container>
6+
<label>Size</label>
7+
<md-select ng-model="size">
8+
<md-option ng-repeat="size in sizes" value="{{size}}">{{size}}</md-option>
9+
</md-select>
10+
</md-input-container>
11+
<md-input-container>
12+
<label>Topping</label>
13+
<md-select ng-model="topping">
14+
<md-optgroup label="Meats">
15+
<md-option ng-value="topping.name" ng-repeat="topping in toppings | filter: {category: 'meat' }">{{topping.name}}</md-option>
16+
</md-optgroup>
17+
<md-optgroup label="Veggies">
18+
<md-option ng-value="topping.name" ng-repeat="topping in toppings | filter: {category: 'veg' }">{{topping.name}}</md-option>
19+
</md-optgroup>
20+
</md-select>
21+
</md-input-container>
1622
</div>
1723
<p ng-if="topping">You ordered a {{size.toLowerCase()}} pizza with {{topping.toLowerCase()}}.</p>
1824
</div>

src/components/select/demoOptionsWithAsyncSearch/index.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<div ng-controller="SelectAsyncController" layout="column" layout-align="center center" style="padding:40px">
22
<p>Select can call an arbitrary function on show. If this function returns a promise, it will display a loading indicator while it is being resolved:</p>
33
<div layout="column" layout-align="center center" style="height: 100px;">
4-
<md-select ng-model="user" md-on-open="loadUsers()" style="min-width: 200px;">
5-
<md-select-label>{{ user ? user.name : 'Assign to user' }}</md-select-label>
4+
<md-select placeholder="Assign to user" ng-model="user" md-on-open="loadUsers()" style="min-width: 200px;">
65
<md-option ng-value="user" ng-repeat="user in users">{{user.name}}</md-option>
76
</md-select>
87
<p class="md-caption">You have assigned the task to: {{ user ? user.name : 'No one yet' }}</p>

src/components/select/demoValidations/index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<form name="myForm">
33
<p>Note that invalid styling only applies if invalid and dirty</p>
44
<md-input-container>
5-
<md-select name="myModel" placeholder="Pick" ng-model="myModel" required>
5+
<label>Favorite Number</label>
6+
<md-select name="myModel" ng-model="myModel" required>
67
<md-option value="1">One</md-option>
78
<md-option value="2">Two</md-option>
89
</md-select>

src/components/select/select-theme.scss

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
md-select.md-THEME_NAME-theme {
2+
.md-select-value {
3+
&.md-select-placeholder {
4+
color: '{{foreground-3}}';
5+
}
6+
border-bottom-color: '{{foreground-4}}';
7+
}
28
&.ng-invalid.ng-dirty {
39
.md-select-label {
410
color: '{{warn-500}}' !important;
511
border-bottom-color: '{{warn-500}}' !important;
612
}
713
}
814
&:not([disabled]):focus {
9-
.md-select-label {
15+
.md-select-value {
1016
border-bottom-color: '{{primary-color}}';
1117
color: '{{ foreground-1 }}';
12-
&.md-placeholder {
18+
&.md-select-placeholder {
1319
color: '{{ foreground-1 }}';
1420
}
1521
}
16-
&.md-accent .md-select-label {
22+
&.md-accent .md-select-value {
1723
border-bottom-color: '{{accent-color}}';
1824
}
19-
&.md-warn .md-select-label {
25+
&.md-warn .md-select-value {
2026
border-bottom-color: '{{warn-color}}';
2127
}
2228
}
2329
&[disabled] {
24-
.md-select-label {
30+
.md-select-value {
2531
color: '{{foreground-3}}';
26-
&.md-placeholder {
32+
&.md-select-placeholder {
2733
color: '{{foreground-3}}';
2834
}
2935
}
3036
}
31-
.md-select-label {
32-
&.md-placeholder {
33-
color: '{{foreground-2}}';
34-
}
35-
border-bottom-color: '{{foreground-4}}';
36-
}
3737
}
3838

3939
md-select-menu.md-THEME_NAME-theme {

0 commit comments

Comments
 (0)