@@ -33,7 +33,7 @@ export const ButtonGroupAlignment = mkenum({
33
33
horizontal : 'horizontal' ,
34
34
vertical : 'vertical'
35
35
} ) ;
36
- export type ButtonGroupAlignment = ( typeof ButtonGroupAlignment ) [ keyof typeof ButtonGroupAlignment ] ;
36
+ export type ButtonGroupAlignment = typeof ButtonGroupAlignment [ keyof typeof ButtonGroupAlignment ] ;
37
37
38
38
let NEXT_ID = 0 ;
39
39
@@ -61,7 +61,6 @@ let NEXT_ID = 0;
61
61
selector : 'igx-buttongroup' ,
62
62
templateUrl : 'buttongroup-content.component.html'
63
63
} )
64
-
65
64
export class IgxButtonGroupComponent extends DisplayDensityBase implements AfterContentInit , AfterViewInit , OnDestroy {
66
65
/**
67
66
* A collection containing all buttons inside the button group.
@@ -123,6 +122,7 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
123
122
* ```
124
123
*/
125
124
@Input ( ) public multiSelection = false ;
125
+
126
126
/**
127
127
* An @Input property that allows setting the buttons in the button group.
128
128
* ```typescript
@@ -150,6 +150,7 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
150
150
* ```
151
151
*/
152
152
@Input ( ) public values : any ;
153
+
153
154
/**
154
155
* An @Input property that allows you to disable the `igx-buttongroup` component. By default it's false.
155
156
* ```html
@@ -165,7 +166,7 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
165
166
this . _disabled = value ;
166
167
167
168
if ( this . viewButtons && this . templateButtons ) {
168
- this . buttons . forEach ( ( b ) => b . disabled = this . _disabled ) ;
169
+ this . buttons . forEach ( ( b ) => ( b . disabled = this . _disabled ) ) ;
169
170
}
170
171
}
171
172
}
@@ -238,7 +239,6 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
238
239
@ViewChildren ( IgxButtonDirective ) private viewButtons : QueryList < IgxButtonDirective > ;
239
240
@ContentChildren ( IgxButtonDirective ) private templateButtons : QueryList < IgxButtonDirective > ;
240
241
241
-
242
242
/**
243
243
* Returns true if the `igx-buttongroup` alignment is vertical.
244
244
* Note that in order for the accessor to work correctly the property should be set explicitly.
@@ -264,14 +264,18 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
264
264
public selectedIndexes : number [ ] = [ ] ;
265
265
266
266
protected buttonClickNotifier$ = new Subject < boolean > ( ) ;
267
+ protected buttonSelectedNotifier$ = new Subject < boolean > ( ) ;
267
268
protected queryListNotifier$ = new Subject < boolean > ( ) ;
268
269
269
270
private _isVertical : boolean ;
270
271
private _itemContentCssClass : string ;
271
272
private _disabled = false ;
272
273
273
- constructor ( private _cdr : ChangeDetectorRef , private _renderer : Renderer2 ,
274
- @Optional ( ) @Inject ( DisplayDensityToken ) protected _displayDensityOptions : IDisplayDensityOptions ) {
274
+ constructor (
275
+ private _cdr : ChangeDetectorRef ,
276
+ private _renderer : Renderer2 ,
277
+ @Optional ( ) @Inject ( DisplayDensityToken ) protected _displayDensityOptions : IDisplayDensityOptions
278
+ ) {
275
279
super ( _displayDensityOptions ) ;
276
280
}
277
281
@@ -308,15 +312,23 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
308
312
}
309
313
310
314
const button = this . buttons [ index ] ;
311
- const buttonElement = button . nativeElement ;
315
+ button . select ( ) ;
316
+ }
312
317
313
- this . selectedIndexes . push ( index ) ;
314
- button . selected = true ;
318
+ /**
319
+ * @hidden
320
+ * @internal
321
+ */
322
+ public updateSelected ( index : number ) {
323
+ const button = this . buttons [ index ] ;
315
324
316
- this . _renderer . setAttribute ( buttonElement , 'aria-pressed' , 'true' ) ;
317
- this . _renderer . addClass ( buttonElement , 'igx-button-group__item--selected' ) ;
325
+ if ( this . selectedIndexes . indexOf ( index ) === - 1 ) {
326
+ this . selectedIndexes . push ( index ) ;
327
+ this . selected . emit ( { button, index } ) ;
328
+ }
318
329
319
- this . selected . emit ( { button, index } ) ;
330
+ this . _renderer . setAttribute ( button . nativeElement , 'aria-pressed' , 'true' ) ;
331
+ this . _renderer . addClass ( button . nativeElement , 'igx-button-group__item--selected' ) ;
320
332
321
333
const indexInViewButtons = this . viewButtons . toArray ( ) . indexOf ( button ) ;
322
334
if ( indexInViewButtons !== - 1 ) {
@@ -352,20 +364,18 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
352
364
}
353
365
354
366
const button = this . buttons [ index ] ;
355
- const buttonElement = button . nativeElement ;
356
-
357
367
this . selectedIndexes . splice ( this . selectedIndexes . indexOf ( index ) , 1 ) ;
358
- button . selected = false ;
359
-
360
- this . _renderer . setAttribute ( buttonElement , 'aria-pressed' , 'false' ) ;
361
- this . _renderer . removeClass ( buttonElement , 'igx-button-group__item--selected' ) ;
362
368
363
- this . deselected . emit ( { button, index } ) ;
369
+ this . _renderer . setAttribute ( button . nativeElement , 'aria-pressed' , 'false' ) ;
370
+ this . _renderer . removeClass ( button . nativeElement , 'igx-button-group__item--selected' ) ;
371
+ button . deselect ( ) ;
364
372
365
373
const indexInViewButtons = this . viewButtons . toArray ( ) . indexOf ( button ) ;
366
374
if ( indexInViewButtons !== - 1 ) {
367
375
this . values [ indexInViewButtons ] . selected = false ;
368
376
}
377
+
378
+ this . deselected . emit ( { button, index } ) ;
369
379
}
370
380
371
381
/**
@@ -392,17 +402,20 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
392
402
// initial configuration
393
403
this . buttons . forEach ( ( button , index ) => {
394
404
const buttonElement = button . nativeElement ;
405
+ this . _renderer . addClass ( buttonElement , 'igx-button-group__item' ) ;
395
406
396
407
if ( this . disabled ) {
397
408
button . disabled = true ;
398
409
}
399
410
400
411
if ( button . selected ) {
401
- this . selectButton ( index ) ;
412
+ this . updateSelected ( index ) ;
402
413
}
403
414
404
- button . buttonClick . pipe ( takeUntil ( this . buttonClickNotifier$ ) ) . subscribe ( ( ev ) => this . _clickHandler ( ev , index ) ) ;
405
- this . _renderer . addClass ( buttonElement , 'igx-button-group__item' ) ;
415
+ button . buttonClick . pipe ( takeUntil ( this . buttonClickNotifier$ ) ) . subscribe ( ( _ ) => this . _clickHandler ( index ) ) ;
416
+ button . buttonSelected
417
+ . pipe ( takeUntil ( this . buttonSelectedNotifier$ ) )
418
+ . subscribe ( ( _ ) => this . updateSelected ( index ) ) ;
406
419
} ) ;
407
420
} ;
408
421
@@ -420,18 +433,21 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
420
433
this . buttonClickNotifier$ . next ( ) ;
421
434
this . buttonClickNotifier$ . complete ( ) ;
422
435
436
+ this . buttonSelectedNotifier$ . next ( ) ;
437
+ this . buttonSelectedNotifier$ . complete ( ) ;
438
+
423
439
this . queryListNotifier$ . next ( ) ;
424
440
this . queryListNotifier$ . complete ( ) ;
425
441
}
426
442
427
443
/**
428
444
* @hidden
429
445
*/
430
- public _clickHandler ( _ : MouseEvent , i : number ) {
431
- if ( this . selectedIndexes . indexOf ( i ) !== - 1 ) {
432
- this . deselectButton ( i ) ;
433
- } else {
446
+ public _clickHandler ( i : number ) {
447
+ if ( this . selectedIndexes . indexOf ( i ) === - 1 ) {
434
448
this . selectButton ( i ) ;
449
+ } else {
450
+ this . deselectButton ( i ) ;
435
451
}
436
452
}
437
453
}
@@ -449,6 +465,4 @@ export interface IButtonGroupEventArgs extends IBaseEventArgs {
449
465
exports : [ IgxButtonGroupComponent ] ,
450
466
imports : [ IgxButtonModule , CommonModule , IgxRippleModule , IgxIconModule ]
451
467
} )
452
-
453
- export class IgxButtonGroupModule {
454
- }
468
+ export class IgxButtonGroupModule { }
0 commit comments