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

Commit 6333b72

Browse files
committed
fix(input): dont add focus/blur class if readonly
Closes #1203.
1 parent f3af15a commit 6333b72

2 files changed

Lines changed: 24 additions & 9 deletions

File tree

src/components/input/input.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ function inputTextareaDirective($mdUtil, $window, $compile, $animate) {
172172

173173
var containerCtrl = ctrls[0];
174174
var ngModelCtrl = ctrls[1] || $mdUtil.fakeNgModel();
175+
var isReadonly = angular.isDefined(attr.readonly);
175176

176177
if ( !containerCtrl ) return;
177178
if (containerCtrl.input) {
@@ -205,15 +206,18 @@ function inputTextareaDirective($mdUtil, $window, $compile, $animate) {
205206
ngModelCtrl.$parsers.push(ngModelPipelineCheckValue);
206207
ngModelCtrl.$formatters.push(ngModelPipelineCheckValue);
207208

208-
element
209-
.on('input', inputCheckValue)
210-
.on('focus', function(ev) {
211-
containerCtrl.setFocused(true);
212-
})
213-
.on('blur', function(ev) {
214-
containerCtrl.setFocused(false);
215-
inputCheckValue();
216-
});
209+
element.on('input', inputCheckValue);
210+
211+
if (!isReadonly) {
212+
element
213+
.on('focus', function(ev) {
214+
containerCtrl.setFocused(true);
215+
})
216+
.on('blur', function(ev) {
217+
containerCtrl.setFocused(false);
218+
inputCheckValue();
219+
});
220+
}
217221

218222
scope.$on('$destroy', function() {
219223
containerCtrl.setFocused(false);

src/components/input/input.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ describe('md-input-container directive', function() {
2323
expect(el).not.toHaveClass('md-input-focused');
2424
});
2525

26+
it('not should set focus class on container if readonly', function() {
27+
var el = setup('readonly');
28+
expect(el).not.toHaveClass('md-input-focused');
29+
30+
el.find('input').triggerHandler('focus');
31+
expect(el).not.toHaveClass('md-input-focused');
32+
33+
el.find('input').triggerHandler('blur');
34+
expect(el).not.toHaveClass('md-input-focused');
35+
});
36+
2637
it('should set has-value class on container for non-ng-model input', function() {
2738
var el = setup();
2839
expect(el).not.toHaveClass('md-input-has-value');

0 commit comments

Comments
 (0)