diff --git a/src/components/input/input.js b/src/components/input/input.js index b0178d5dc6b..288824716e4 100644 --- a/src/components/input/input.js +++ b/src/components/input/input.js @@ -172,6 +172,7 @@ function inputTextareaDirective($mdUtil, $window, $compile, $animate) { var containerCtrl = ctrls[0]; var ngModelCtrl = ctrls[1] || $mdUtil.fakeNgModel(); + var isReadonly = angular.isDefined(attr.readonly); if ( !containerCtrl ) return; if (containerCtrl.input) { @@ -205,15 +206,18 @@ function inputTextareaDirective($mdUtil, $window, $compile, $animate) { ngModelCtrl.$parsers.push(ngModelPipelineCheckValue); ngModelCtrl.$formatters.push(ngModelPipelineCheckValue); - element - .on('input', inputCheckValue) - .on('focus', function(ev) { - containerCtrl.setFocused(true); - }) - .on('blur', function(ev) { - containerCtrl.setFocused(false); - inputCheckValue(); - }); + element.on('input', inputCheckValue); + + if (!isReadonly) { + element + .on('focus', function(ev) { + containerCtrl.setFocused(true); + }) + .on('blur', function(ev) { + containerCtrl.setFocused(false); + inputCheckValue(); + }); + } scope.$on('$destroy', function() { containerCtrl.setFocused(false); diff --git a/src/components/input/input.spec.js b/src/components/input/input.spec.js index 87f5801346f..90f4e1f9c29 100644 --- a/src/components/input/input.spec.js +++ b/src/components/input/input.spec.js @@ -23,6 +23,17 @@ describe('md-input-container directive', function() { expect(el).not.toHaveClass('md-input-focused'); }); + it('not should set focus class on container if readonly', function() { + var el = setup('readonly'); + expect(el).not.toHaveClass('md-input-focused'); + + el.find('input').triggerHandler('focus'); + expect(el).not.toHaveClass('md-input-focused'); + + el.find('input').triggerHandler('blur'); + expect(el).not.toHaveClass('md-input-focused'); + }); + it('should set has-value class on container for non-ng-model input', function() { var el = setup(); expect(el).not.toHaveClass('md-input-has-value');