Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/select/demoBasicUsage/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

<div layout="row" layout-align="space-between center">
<span>What armor do you wear?</span>
<md-select ng-model="armor" placeholder="Armor" class="md-no-underline" required>
<md-select ng-model="armor" placeholder="Armor" class="md-no-underline" required md-no-asterisk="false">
<md-option value="cloth">Cloth</md-option>
<md-option value="leather">Leather</md-option>
<md-option value="chain">Chainmail</md-option>
Expand Down
8 changes: 6 additions & 2 deletions src/components/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ angular.module('material.components.select', [
* @param {expression=} md-selected-text Expression to be evaluated that will return a string
* to be displayed as a placeholder in the select input box when it is closed.
* @param {string=} placeholder Placeholder hint text.
* @param md-no-asterisk {boolean=} When set to true, an asterisk will not be appended to the floating label.
* @param md-no-asterisk {boolean=} When set to true, an asterisk will not be appended to the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this an opt-out? Would an opt-in not be a better approach?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have always pushed for the opt-in approach; however, this has been around since before 1.0 (before I joined the team I think) so I don't think we should change the API at this point.

All I did here was add a note about it only being evaluated once; not being watched.

* floating label. **Note:** This attribute is only evaluated once; it is not watched.
* @param {string=} aria-label Optional label for accessibility. Only necessary if no placeholder or
* explicit label is present.
* @param {string=} md-container-class Class list to get applied to the `.md-select-menu-container`
Expand Down Expand Up @@ -273,6 +274,10 @@ function SelectDirective($mdSelect, $mdUtil, $mdConstant, $mdTheming, $mdAria, $
var isReadonly = angular.isDefined(attr.readonly);
var disableAsterisk = $mdUtil.parseAttributeBoolean(attr.mdNoAsterisk);

if (disableAsterisk) {
element.addClass('md-no-asterisk');
}

if (containerCtrl) {
var isErrorGetter = containerCtrl.isErrorGetter || function() {
return ngModelCtrl.$invalid && (ngModelCtrl.$touched || (formCtrl && formCtrl.$submitted));
Expand Down Expand Up @@ -316,7 +321,6 @@ function SelectDirective($mdSelect, $mdUtil, $mdConstant, $mdTheming, $mdAria, $
inputCheckValue();
};


attr.$observe('placeholder', ngModelCtrl.$render);

if (containerCtrl && containerCtrl.label) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/select/select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ md-input-container > md-select {
// NOTE: When the input has a value and uses a floating label, the floating label will show the
// asterisk denoting that it is required
md-input-container:not(.md-input-has-value) {
md-select[required], md-select.ng-required {
md-select[required]:not(.md-no-asterisk), md-select.ng-required:not(.md-no-asterisk) {
.md-select-value span:first-child:after {
content: ' *';
font-size: 13px;
Expand All @@ -105,7 +105,7 @@ md-select {
margin: 2.5*$baseline-grid 0 3*$baseline-grid + 2 0;

&[required], &.ng-required {
&.ng-invalid {
&.ng-invalid:not(.md-no-asterisk) {
.md-select-value span:first-child:after {
content: ' *';
font-size: 13px;
Expand Down
20 changes: 20 additions & 0 deletions src/components/select/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,26 @@ describe('<md-select>', function() {
expect(label).not.toHaveClass('md-required');
}));

it('correctly adds the .md-no-asterisk class if the attribute is empty', function() {
var el = setupSelect('ng-required="isRequired" md-no-asterisk ng-model="someModel"');
var select = el.find('md-select');

expect(select).toHaveClass('md-no-asterisk');
});

it('correctly adds the .md-no-asterisk class if the attribute is true', function() {
var el = setupSelect('ng-required="isRequired" md-no-asterisk ng-model="someModel"');
var select = el.find('md-select');

expect(select).toHaveClass('md-no-asterisk');
});

it('correctly removes the .md-no-asterisk class if the attribute is false', function() {
var el = setupSelect('ng-required="isRequired" md-no-asterisk="false" ng-model="someModel"');
var select = el.find('md-select');

expect(select).not.toHaveClass('md-no-asterisk');
});
});

describe('view->model', function() {
Expand Down