Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/components/input/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ angular.module('material.components.input', [
* </hljs>
*/
function mdInputContainerDirective($mdTheming, $parse) {

var INPUT_TAGS = ['INPUT', 'TEXTAREA', 'MD-SELECT'];

return {
restrict: 'E',
link: postLink,
Expand All @@ -71,8 +74,8 @@ function mdInputContainerDirective($mdTheming, $parse) {
var next = icons[0].nextElementSibling;
var previous = icons[0].previousElementSibling;

element.addClass(next && next.tagName === 'INPUT' ? 'md-icon-left' :
previous && previous.tagName === 'INPUT' ? 'md-icon-right' : '');
element.addClass(next && INPUT_TAGS.indexOf(next.tagName) != -1 ? 'md-icon-left' :
previous && INPUT_TAGS.indexOf(previous.tagName) != -1 ? 'md-icon-right' : '');
}
// In case there are two icons we apply both icon classes
else if (icons.length == 2) {
Expand Down
44 changes: 44 additions & 0 deletions src/components/input/input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,5 +539,49 @@ describe('md-input-container directive', function() {
);
expect(el.hasClass('md-icon-left md-icon-right')).toBeTruthy();
});

it('should add md-icon-left class when md-icon is before select', function() {
var el = compile(
'<md-input-container>' +
'<md-icon></md-icon>' +
'<md-select ng-model="foo"></md-select>' +
'</md-input-container>'
);

expect(el.hasClass('md-icon-left')).toBeTruthy();
});

it('should add md-icon-right class when md-icon is before select', function() {
var el = compile(
'<md-input-container>' +
'<md-select ng-model="foo"></md-select>' +
'<md-icon></md-icon>' +
'</md-input-container>'
);

expect(el.hasClass('md-icon-right')).toBeTruthy();
});

it('should add md-icon-left class when md-icon is before textarea', function() {
var el = compile(
'<md-input-container>' +
'<md-icon></md-icon>' +
'<textarea ng-model="foo"></textarea>' +
'</md-input-container>'
);

expect(el.hasClass('md-icon-left')).toBeTruthy();
});

it('should add md-icon-right class when md-icon is before textarea', function() {
var el = compile(
'<md-input-container>' +
'<textarea ng-model="foo"></textarea>' +
'<md-icon></md-icon>' +
'</md-input-container>'
);

expect(el.hasClass('md-icon-right')).toBeTruthy();
});
});
});