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

Commit 7778a9c

Browse files
devversionThomasBurleson
authored andcommitted
fix(input): smart icon support for input, textarea, select
Fixes #6977.Closes #6979.
1 parent 179dc19 commit 7778a9c

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

src/components/input/input.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ angular.module('material.components.input', [
6363
* </hljs>
6464
*/
6565
function mdInputContainerDirective($mdTheming, $parse) {
66+
67+
var INPUT_TAGS = ['INPUT', 'TEXTAREA', 'MD-SELECT'];
68+
6669
return {
6770
restrict: 'E',
6871
link: postLink,
@@ -80,8 +83,8 @@ function mdInputContainerDirective($mdTheming, $parse) {
8083
var next = icons[0].nextElementSibling;
8184
var previous = icons[0].previousElementSibling;
8285

83-
element.addClass(next && next.tagName === 'INPUT' ? 'md-icon-left' :
84-
previous && previous.tagName === 'INPUT' ? 'md-icon-right' : '');
86+
element.addClass(next && INPUT_TAGS.indexOf(next.tagName) != -1 ? 'md-icon-left' :
87+
previous && INPUT_TAGS.indexOf(previous.tagName) != -1 ? 'md-icon-right' : '');
8588
}
8689
// In case there are two icons we apply both icon classes
8790
else if (icons.length == 2) {

src/components/input/input.spec.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,5 +539,49 @@ describe('md-input-container directive', function() {
539539
);
540540
expect(el.hasClass('md-icon-left md-icon-right')).toBeTruthy();
541541
});
542+
543+
it('should add md-icon-left class when md-icon is before select', function() {
544+
var el = compile(
545+
'<md-input-container>' +
546+
'<md-icon></md-icon>' +
547+
'<md-select ng-model="foo"></md-select>' +
548+
'</md-input-container>'
549+
);
550+
551+
expect(el.hasClass('md-icon-left')).toBeTruthy();
552+
});
553+
554+
it('should add md-icon-right class when md-icon is before select', function() {
555+
var el = compile(
556+
'<md-input-container>' +
557+
'<md-select ng-model="foo"></md-select>' +
558+
'<md-icon></md-icon>' +
559+
'</md-input-container>'
560+
);
561+
562+
expect(el.hasClass('md-icon-right')).toBeTruthy();
563+
});
564+
565+
it('should add md-icon-left class when md-icon is before textarea', function() {
566+
var el = compile(
567+
'<md-input-container>' +
568+
'<md-icon></md-icon>' +
569+
'<textarea ng-model="foo"></textarea>' +
570+
'</md-input-container>'
571+
);
572+
573+
expect(el.hasClass('md-icon-left')).toBeTruthy();
574+
});
575+
576+
it('should add md-icon-right class when md-icon is before textarea', function() {
577+
var el = compile(
578+
'<md-input-container>' +
579+
'<textarea ng-model="foo"></textarea>' +
580+
'<md-icon></md-icon>' +
581+
'</md-input-container>'
582+
);
583+
584+
expect(el.hasClass('md-icon-right')).toBeTruthy();
585+
});
542586
});
543587
});

0 commit comments

Comments
 (0)