From 21695be7ef14a31d96eb3aae1b57782b9506e73f Mon Sep 17 00:00:00 2001 From: crisbeto Date: Sat, 30 Apr 2016 23:03:53 +0200 Subject: [PATCH] fix(input): duplicate placeholders and data bindings aria-label * Fixes the element label being duplicated, if it has a data binding in the placeholder attribute. This was caused by Angular re-adding the placeholder attribute, even though it was removed by the Material placeholder directive. * Fixes the aria-label getting the raw data binding (e.g. `aria-label="{{expression}}"`), when it's gets taken from a dynamic placeholder. Fixes #8251. Fixes #8377. --- src/components/input/input.js | 44 +++++++++++++------- src/components/input/input.spec.js | 65 ++++++++++++++++++++++++------ 2 files changed, 82 insertions(+), 27 deletions(-) diff --git a/src/components/input/input.js b/src/components/input/input.js index 3d2888b52d8..0fcd1704b43 100644 --- a/src/components/input/input.js +++ b/src/components/input/input.js @@ -308,7 +308,7 @@ function inputTextareaDirective($mdUtil, $window, $mdAria, $timeout, $mdGesture) element.after(errorsSpacer); if (!containerCtrl.label) { - $mdAria.expect(element, 'aria-label', element.attr('placeholder')); + $mdAria.expect(element, 'aria-label', attr.placeholder); } element.addClass('md-input'); @@ -660,15 +660,22 @@ function mdMaxlengthDirective($animate, $mdUtil) { } } -function placeholderDirective($log) { +function placeholderDirective($compile) { return { restrict: 'A', require: '^^?mdInputContainer', priority: 200, - link: postLink + link: { + // Note that we need to do this in the pre-link, as opposed to the post link, if we want to + // support data bindings in the placeholder. This is necessary, because we have a case where + // we transfer the placeholder value to the `