@@ -54,7 +54,7 @@ function MdCheckboxDirective(inputDirective, $mdAria, $mdConstant, $mdTheming, $
54
54
restrict : 'E' ,
55
55
transclude : true ,
56
56
require : '?ngModel' ,
57
- priority :210 , // Run before ngAria
57
+ priority : 210 , // Run before ngAria
58
58
template :
59
59
'<div class="md-container" md-ink-ripple md-ink-ripple-checkbox>' +
60
60
'<div class="md-icon"></div>' +
@@ -73,6 +73,14 @@ function MdCheckboxDirective(inputDirective, $mdAria, $mdConstant, $mdTheming, $
73
73
tAttrs . tabindex = tAttrs . tabindex || '0' ;
74
74
tElement . attr ( 'role' , tAttrs . type ) ;
75
75
76
+ // Attach a click handler in compile in order to immediately stop propagation
77
+ // (especially for ng-click) when the checkbox is disabled.
78
+ tElement . on ( 'click' , function ( event ) {
79
+ if ( this . hasAttribute ( 'disabled' ) ) {
80
+ event . stopImmediatePropagation ( ) ;
81
+ }
82
+ } ) ;
83
+
76
84
return function postLink ( scope , element , attr , ngModelCtrl ) {
77
85
ngModelCtrl = ngModelCtrl || $mdUtil . fakeNgModel ( ) ;
78
86
$mdTheming ( element ) ;
@@ -83,10 +91,12 @@ function MdCheckboxDirective(inputDirective, $mdAria, $mdConstant, $mdTheming, $
83
91
ngModelCtrl . $setViewValue . bind ( ngModelCtrl )
84
92
) ;
85
93
}
94
+
86
95
$$watchExpr ( 'ngDisabled' , 'tabindex' , {
87
96
true : '-1' ,
88
97
false : attr . tabindex
89
98
} ) ;
99
+
90
100
$mdAria . expectWithText ( element , 'aria-label' ) ;
91
101
92
102
// Reuse the original input[type=checkbox] directive from Angular core.
@@ -102,14 +112,18 @@ function MdCheckboxDirective(inputDirective, $mdAria, $mdConstant, $mdTheming, $
102
112
. on ( 'keypress' , keypressHandler )
103
113
. on ( 'mousedown' , function ( ) {
104
114
scope . mouseActive = true ;
105
- $timeout ( function ( ) {
115
+ $timeout ( function ( ) {
106
116
scope . mouseActive = false ;
107
117
} , 100 ) ;
108
118
} )
109
119
. on ( 'focus' , function ( ) {
110
- if ( scope . mouseActive === false ) { element . addClass ( 'md-focused' ) ; }
120
+ if ( scope . mouseActive === false ) {
121
+ element . addClass ( 'md-focused' ) ;
122
+ }
111
123
} )
112
- . on ( 'blur' , function ( ) { element . removeClass ( 'md-focused' ) ; } ) ;
124
+ . on ( 'blur' , function ( ) {
125
+ element . removeClass ( 'md-focused' ) ;
126
+ } ) ;
113
127
114
128
ngModelCtrl . $render = render ;
115
129
@@ -127,12 +141,18 @@ function MdCheckboxDirective(inputDirective, $mdAria, $mdConstant, $mdTheming, $
127
141
var keyCode = ev . which || ev . keyCode ;
128
142
if ( keyCode === $mdConstant . KEY_CODE . SPACE || keyCode === $mdConstant . KEY_CODE . ENTER ) {
129
143
ev . preventDefault ( ) ;
130
- if ( ! element . hasClass ( 'md-focused' ) ) { element . addClass ( 'md-focused' ) ; }
144
+
145
+ if ( ! element . hasClass ( 'md-focused' ) ) {
146
+ element . addClass ( 'md-focused' ) ;
147
+ }
148
+
131
149
listener ( ev ) ;
132
150
}
133
151
}
134
152
function listener ( ev ) {
135
- if ( element [ 0 ] . hasAttribute ( 'disabled' ) ) return ;
153
+ if ( element [ 0 ] . hasAttribute ( 'disabled' ) ) {
154
+ return ;
155
+ }
136
156
137
157
scope . $apply ( function ( ) {
138
158
// Toggle the checkbox value...
0 commit comments