Skip to content

Commit

Permalink
feat(itemFloatingLabel): add floating labels: 'item-floating-label' c…
Browse files Browse the repository at this point in the history
…lass

Closes #1611
  • Loading branch information
tlancina authored and ajoslin committed Jun 12, 2014
1 parent 1a7c1f1 commit 050b4f2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
40 changes: 40 additions & 0 deletions js/angular/directive/itemFloatingLabel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

IonicModule
.directive('itemFloatingLabel', function() {
return {
restrict: 'C',
link: function(scope, element) {
var el = element[0];
var input = el.querySelector('input, textarea');
var inputLabel = el.querySelector('.input-label');

if ( !input || !inputLabel ) return;

var onInput = function() {
var hasInput = inputLabel.classList.contains('has-input');
if ( input.value && !hasInput ) {
inputLabel.classList.add('has-input');
}
else if ( !input.value && hasInput ) {
inputLabel.classList.remove('has-input');
}
};

input.addEventListener('input', onInput);

var ngModelCtrl = angular.element(input).controller('ngModel');
if ( ngModelCtrl ) {
ngModelCtrl.$render = function() {
input.value = ngModelCtrl.$viewValue || '';
if ( ngModelCtrl.$viewValue ) input.value = ngModelCtrl.$viewValue;
else input.value = '';
onInput();
};
}

scope.$on('$destroy', function() {
input.removeEventListener('input', onInput);
});
}
};
});
20 changes: 20 additions & 0 deletions scss/_form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,26 @@ textarea {
height: $line-height-computed + $font-size-base + 12px;
}

.item-floating-label {
display: block;
background-color: transparent;
box-shadow: none;

.input-label {
position: relative;
padding: 5px 0 0 0;
opacity: 0;
top: 10px;
@include transition(opacity .2s ease-in, top .2s linear);

&.has-input {
opacity: 1;
top: 0;
@include transition(opacity .2s ease-in, top .2s linear);
}
}
}


// Form Controls
// -------------------------------
Expand Down

0 comments on commit 050b4f2

Please sign in to comment.