Skip to content

Commit

Permalink
ion-label
Browse files Browse the repository at this point in the history
  • Loading branch information
mlynch committed Dec 7, 2015
1 parent 6383933 commit 1a91bb2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions js/angular/directive/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,31 @@ IonicModule
}
};
}]);

IonicModule
.directive('ionLabel', ['$$rAF', function($$rAF) {
return {
restrict: 'E',
scope: true,
require: '?^ionInput',
compile: function($element, $attrs) {

return function link($scope, $element, $attrs, ionInputCtrl) {
var element = $element[0];

$element.addClass('input-label');

$element.attr('aria-label', $element.text());
var id = element.id || '_label-' + ++labelIds;

if(!element.id) {
$element.attr('id', id);
}

if(ionInputCtrl && ionInputCtrl.input) {
ionInputCtrl.input.setAttribute('aria-labelledby', id);
}
}
}
};
}]);
2 changes: 1 addition & 1 deletion test/html/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h1 class="title">Title</h1>
<textarea placeholder="Comments"></textarea>
</ion-input>
<ion-input class="item item-input">
<span class="input-label">Username</span>
<ion-label>Username</ion-label>
<input type="text">
</ion-input>
</div>
Expand Down

0 comments on commit 1a91bb2

Please sign in to comment.