@@ -357,8 +357,6 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
357
357
return ;
358
358
}
359
359
360
- this . updateSelected ( index ) ;
361
-
362
360
const button = this . buttons [ index ] ;
363
361
button . select ( ) ;
364
362
}
@@ -387,12 +385,28 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
387
385
this . buttons . forEach ( ( _ , i ) => {
388
386
if ( i !== index && this . selectedIndexes . indexOf ( i ) !== - 1 ) {
389
387
this . deselectButton ( i ) ;
388
+ this . updateDeselected ( i ) ;
390
389
}
391
390
} ) ;
392
391
}
393
392
394
393
}
395
394
395
+ public updateDeselected ( index : number ) {
396
+ const button = this . buttons [ index ] ;
397
+ if ( this . selectedIndexes . indexOf ( index ) !== - 1 ) {
398
+ this . selectedIndexes . splice ( this . selectedIndexes . indexOf ( index ) , 1 ) ;
399
+ }
400
+
401
+ this . _renderer . setAttribute ( button . nativeElement , 'aria-pressed' , 'false' ) ;
402
+ this . _renderer . removeClass ( button . nativeElement , 'igx-button-group__item--selected' ) ;
403
+
404
+ const indexInViewButtons = this . viewButtons . toArray ( ) . indexOf ( button ) ;
405
+ if ( indexInViewButtons !== - 1 ) {
406
+ this . values [ indexInViewButtons ] . selected = false ;
407
+ }
408
+ }
409
+
396
410
/**
397
411
* Deselects a button by its index.
398
412
* ```typescript
@@ -412,16 +426,7 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
412
426
}
413
427
414
428
const button = this . buttons [ index ] ;
415
- this . selectedIndexes . splice ( this . selectedIndexes . indexOf ( index ) , 1 ) ;
416
-
417
- this . _renderer . setAttribute ( button . nativeElement , 'aria-pressed' , 'false' ) ;
418
- this . _renderer . removeClass ( button . nativeElement , 'igx-button-group__item--selected' ) ;
419
429
button . deselect ( ) ;
420
-
421
- const indexInViewButtons = this . viewButtons . toArray ( ) . indexOf ( button ) ;
422
- if ( indexInViewButtons !== - 1 ) {
423
- this . values [ indexInViewButtons ] . selected = false ;
424
- }
425
430
}
426
431
427
432
/**
@@ -497,8 +502,6 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
497
502
* @hidden
498
503
*/
499
504
public _clickHandler ( index : number ) {
500
- this . mutationObserver . disconnect ( ) ;
501
-
502
505
const button = this . buttons [ index ] ;
503
506
const args : IButtonGroupEventArgs = { owner : this , button, index } ;
504
507
@@ -519,8 +522,6 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
519
522
this . deselected . emit ( args ) ;
520
523
}
521
524
}
522
-
523
- this . mutationObserver ?. observe ( this . _el . nativeElement , this . observerConfig ) ;
524
525
}
525
526
526
527
private setMutationsObserver ( ) {
@@ -544,7 +545,7 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
544
545
observer . observe ( this . _el . nativeElement , this . observerConfig ) ;
545
546
546
547
// Cleanup function
547
- this . _renderer . listen ( this . _el . nativeElement , 'DOMNodeRemoved ' , ( ) => {
548
+ this . _renderer . listen ( this . _el . nativeElement , 'DOMAttrModified ' , ( ) => {
548
549
observer . disconnect ( ) ;
549
550
} ) ;
550
551
} ) ;
@@ -567,11 +568,11 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
567
568
}
568
569
569
570
private updateButtonSelectionState ( index : number , args : IButtonGroupEventArgs ) {
570
- if ( this . selectedIndexes . indexOf ( index ) === - 1 ) {
571
- this . selectButton ( index ) ;
571
+ if ( this . buttons [ index ] . selected ) {
572
+ this . updateSelected ( index ) ;
572
573
this . selected . emit ( args ) ;
573
574
} else {
574
- this . deselectButton ( index ) ;
575
+ this . updateDeselected ( index ) ;
575
576
this . deselected . emit ( args ) ;
576
577
}
577
578
}
0 commit comments