From 1a91bb22b4cf451ed74d395d3f4b3b3b1ff6fa8f Mon Sep 17 00:00:00 2001 From: Max Lynch Date: Mon, 7 Dec 2015 15:23:00 -0600 Subject: [PATCH] ion-label --- js/angular/directive/input.js | 28 ++++++++++++++++++++++++++++ test/html/content.html | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/js/angular/directive/input.js b/js/angular/directive/input.js index b2738c7e684..4cba246547c 100644 --- a/js/angular/directive/input.js +++ b/js/angular/directive/input.js @@ -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); + } + } + } + }; +}]); diff --git a/test/html/content.html b/test/html/content.html index abc9e2449a6..e4d15f61d4e 100644 --- a/test/html/content.html +++ b/test/html/content.html @@ -46,7 +46,7 @@

Title

- Username + Username