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

Commit

Permalink
feat(select): add attribute to allow permanent label showing.
Browse files Browse the repository at this point in the history
Fixes #6286
  • Loading branch information
devversion committed Jan 6, 2016
1 parent 80a8929 commit 963ac18
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/components/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ angular.module('material.components.select', [
*
* @param {expression} ng-model The model!
* @param {boolean=} multiple Whether it's multiple.
* @param {boolean=} md-permanent-label Show the label permanently
* @param {expression=} md-on-close Expression to be evaluated when the select is closed.
* @param {string=} placeholder Placeholder hint text.
* @param {string=} aria-label Optional label for accessibility. Only necessary if no placeholder or
Expand Down Expand Up @@ -132,6 +133,7 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $par
element.append(angular.element('<md-content>').append(element.contents()));
}

var hasPermantentLabel = !!attr.mdPermanentLabel;

// Add progress spinner for md-options-loading
if (attr.mdOnOpen) {
Expand Down Expand Up @@ -215,6 +217,10 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $par
$mdAria.expect(element, 'aria-label', element.attr('placeholder'));
}

if (hasPermantentLabel) {
containerCtrl.setHasValue(true);
}

scope.$watch(isErrorGetter, containerCtrl.setInvalid);
}

Expand Down Expand Up @@ -261,7 +267,7 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $par
};

mdSelectCtrl.setIsPlaceholder = function(isPlaceholder) {
if (isPlaceholder) {
if (isPlaceholder && !hasPermantentLabel) {
valueEl.addClass('md-select-placeholder');
if (containerCtrl && containerCtrl.label) {
containerCtrl.label.addClass('md-placeholder');
Expand Down Expand Up @@ -399,7 +405,7 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $par
.finally(function() {
if (containerCtrl) {
containerCtrl.setFocused(false);
containerCtrl.setHasValue(false);
if (!hasPermantentLabel) containerCtrl.setHasValue(false);
containerCtrl.input = null;
}
});
Expand All @@ -410,7 +416,7 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $par
function inputCheckValue() {
// The select counts as having a value if one or more options are selected,
// or if the input's validity state says it has bad input (eg string in a number input)
containerCtrl && containerCtrl.setHasValue(selectMenuCtrl.selectedLabels().length > 0 || (element[0].validity || {}).badInput);
containerCtrl && !hasPermantentLabel && containerCtrl.setHasValue(selectMenuCtrl.selectedLabels().length > 0 || (element[0].validity || {}).badInput);
}

function findSelectContainer() {
Expand Down

0 comments on commit 963ac18

Please sign in to comment.