@@ -357,8 +357,6 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
357357 return ;
358358 }
359359
360- this . updateSelected ( index ) ;
361-
362360 const button = this . buttons [ index ] ;
363361 button . select ( ) ;
364362 }
@@ -387,12 +385,28 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
387385 this . buttons . forEach ( ( _ , i ) => {
388386 if ( i !== index && this . selectedIndexes . indexOf ( i ) !== - 1 ) {
389387 this . deselectButton ( i ) ;
388+ this . updateDeselected ( i ) ;
390389 }
391390 } ) ;
392391 }
393392
394393 }
395394
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+
396410 /**
397411 * Deselects a button by its index.
398412 * ```typescript
@@ -412,16 +426,7 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
412426 }
413427
414428 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' ) ;
419429 button . deselect ( ) ;
420-
421- const indexInViewButtons = this . viewButtons . toArray ( ) . indexOf ( button ) ;
422- if ( indexInViewButtons !== - 1 ) {
423- this . values [ indexInViewButtons ] . selected = false ;
424- }
425430 }
426431
427432 /**
@@ -497,8 +502,6 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
497502 * @hidden
498503 */
499504 public _clickHandler ( index : number ) {
500- this . mutationObserver . disconnect ( ) ;
501-
502505 const button = this . buttons [ index ] ;
503506 const args : IButtonGroupEventArgs = { owner : this , button, index } ;
504507
@@ -519,8 +522,6 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
519522 this . deselected . emit ( args ) ;
520523 }
521524 }
522-
523- this . mutationObserver ?. observe ( this . _el . nativeElement , this . observerConfig ) ;
524525 }
525526
526527 private setMutationsObserver ( ) {
@@ -544,7 +545,7 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
544545 observer . observe ( this . _el . nativeElement , this . observerConfig ) ;
545546
546547 // Cleanup function
547- this . _renderer . listen ( this . _el . nativeElement , 'DOMNodeRemoved ' , ( ) => {
548+ this . _renderer . listen ( this . _el . nativeElement , 'DOMAttrModified ' , ( ) => {
548549 observer . disconnect ( ) ;
549550 } ) ;
550551 } ) ;
@@ -567,11 +568,11 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
567568 }
568569
569570 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 ) ;
572573 this . selected . emit ( args ) ;
573574 } else {
574- this . deselectButton ( index ) ;
575+ this . updateDeselected ( index ) ;
575576 this . deselected . emit ( args ) ;
576577 }
577578 }
0 commit comments