@@ -62,7 +62,7 @@ function mdRadioGroupDirective($mdUtil, $mdConstant, $mdTheming, $timeout) {
62
62
function linkRadioGroup ( scope , element , attr , ctrls ) {
63
63
element . addClass ( '_md' ) ; // private md component indicator for styling
64
64
$mdTheming ( element ) ;
65
-
65
+
66
66
var rgCtrl = ctrls [ 0 ] ;
67
67
var ngModelCtrl = ctrls [ 1 ] || $mdUtil . fakeNgModel ( ) ;
68
68
@@ -205,8 +205,6 @@ function mdRadioGroupDirective($mdUtil, $mdConstant, $mdTheming, $timeout) {
205
205
206
206
// Activate radioButton's click listener (triggerHandler won't create a real click event)
207
207
angular . element ( target ) . triggerHandler ( 'click' ) ;
208
-
209
-
210
208
}
211
209
}
212
210
@@ -272,10 +270,18 @@ function mdRadioButtonDirective($mdAria, $mdUtil, $mdTheming) {
272
270
$mdTheming ( element ) ;
273
271
configureAria ( element , scope ) ;
274
272
275
- initialize ( ) ;
273
+ // ngAria overwrites the aria-checked inside a $watch for ngValue.
274
+ // We should defer the initialization until all the watches have fired.
275
+ // This can also be fixed by removing the `lastChecked` check, but that'll
276
+ // cause more DOM manipulation on each digest.
277
+ if ( attr . ngValue ) {
278
+ $mdUtil . nextTick ( initialize , false ) ;
279
+ } else {
280
+ initialize ( ) ;
281
+ }
276
282
277
283
/**
278
- *
284
+ * Initializes the component.
279
285
*/
280
286
function initialize ( ) {
281
287
if ( ! rgCtrl ) {
@@ -293,7 +299,7 @@ function mdRadioButtonDirective($mdAria, $mdUtil, $mdTheming) {
293
299
}
294
300
295
301
/**
296
- *
302
+ * On click functionality.
297
303
*/
298
304
function listener ( ev ) {
299
305
if ( element [ 0 ] . hasAttribute ( 'disabled' ) || rgCtrl . isDisabled ( ) ) return ;
@@ -308,58 +314,37 @@ function mdRadioButtonDirective($mdAria, $mdUtil, $mdTheming) {
308
314
* Update the `aria-activedescendant` attribute.
309
315
*/
310
316
function render ( ) {
311
- var checked = ( rgCtrl . getViewValue ( ) == attr . value ) ;
312
- if ( checked === lastChecked ) {
313
- return ;
314
- }
317
+ var checked = rgCtrl . getViewValue ( ) == attr . value ;
315
318
316
- lastChecked = checked ;
317
- element . attr ( 'aria-checked' , checked ) ;
319
+ if ( checked === lastChecked ) return ;
318
320
319
- if ( checked ) {
320
- markParentAsChecked ( true ) ;
321
- element . addClass ( CHECKED_CSS ) ;
321
+ if ( element [ 0 ] . parentNode . nodeName . toLowerCase ( ) !== 'md-radio-group' ) {
322
+ // If the radioButton is inside a div, then add class so highlighting will work
323
+ element . parent ( ) . toggleClass ( CHECKED_CSS , checked ) ;
324
+ }
322
325
326
+ if ( checked ) {
323
327
rgCtrl . setActiveDescendant ( element . attr ( 'id' ) ) ;
324
-
325
- } else {
326
- markParentAsChecked ( false ) ;
327
- element . removeClass ( CHECKED_CSS ) ;
328
328
}
329
329
330
- /**
331
- * If the radioButton is inside a div, then add class so highlighting will work...
332
- */
333
- function markParentAsChecked ( addClass ) {
334
- if ( element . parent ( ) [ 0 ] . nodeName != "MD-RADIO-GROUP" ) {
335
- element . parent ( ) [ ! ! addClass ? 'addClass' : 'removeClass' ] ( CHECKED_CSS ) ;
336
- }
330
+ lastChecked = checked ;
337
331
338
- }
332
+ element
333
+ . attr ( 'aria-checked' , checked )
334
+ . toggleClass ( CHECKED_CSS , checked ) ;
339
335
}
340
336
341
337
/**
342
338
* Inject ARIA-specific attributes appropriate for each radio button
343
339
*/
344
- function configureAria ( element , scope ) {
345
- scope . ariaId = buildAriaID ( ) ;
346
-
340
+ function configureAria ( element , scope ) {
347
341
element . attr ( {
348
- 'id' : scope . ariaId ,
349
- ' role' : 'radio' ,
350
- 'aria-checked' : 'false'
342
+ id : attr . id || 'radio_' + $mdUtil . nextUid ( ) ,
343
+ role : 'radio' ,
344
+ 'aria-checked' : 'false'
351
345
} ) ;
352
346
353
347
$mdAria . expectWithText ( element , 'aria-label' ) ;
354
-
355
- /**
356
- * Build a unique ID for each radio button that will be used with aria-activedescendant.
357
- * Preserve existing ID if already specified.
358
- * @returns {*|string }
359
- */
360
- function buildAriaID ( ) {
361
- return attr . id || ( 'radio' + "_" + $mdUtil . nextUid ( ) ) ;
362
- }
363
348
}
364
349
}
365
350
}
0 commit comments