Skip to content

Commit 01ce73b

Browse files
authored
Merge pull request #13631 from IgniteUI/ganastasov/fix-13580-16.1
fix(button-group): reverted cancellable on selected and deselected events - 16.1
2 parents 74737fa + 25acf88 commit 01ce73b

File tree

3 files changed

+11
-51
lines changed

3 files changed

+11
-51
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
All notable changes for each version of this project will be documented in this file.
44

5+
## 16.1.5
6+
### General
7+
- `IgxButtonGroup`:
8+
- Reverted cancellable on `selected` and `deselected` events (added in 15.1.24) as it was breaking firing order and related handling.
9+
510
## 16.1.4
611
### New Features
712
- `Themes`:

projects/igniteui-angular/src/lib/buttonGroup/buttonGroup.component.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { IgxRippleDirective } from '../directives/ripple/ripple.directive';
2323

2424
import { takeUntil } from 'rxjs/operators';
2525
import { DisplayDensityBase, DisplayDensityToken, IDisplayDensityOptions } from '../core/density';
26-
import { CancelableEventArgs, IBaseEventArgs } from '../core/utils';
26+
import { IBaseEventArgs } from '../core/utils';
2727
import { mkenum } from '../core/utils';
2828
import { IgxIconComponent } from '../icon/icon.component';
2929

@@ -481,33 +481,29 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
481481
*/
482482
public _clickHandler(index: number) {
483483
const button = this.buttons[index];
484-
const args: IButtonGroupEventArgs = { cancel: false, owner: this, button, index };
484+
const args: IButtonGroupEventArgs = { owner: this, button, index };
485485

486486
if (this.selectionMode !== 'multi') {
487487
this.buttons.forEach((b, i) => {
488488
if (i !== index && this.selectedIndexes.indexOf(i) !== -1) {
489-
this.deselected.emit({ cancel: false, owner: this, button: b, index: i });
489+
this.deselected.emit({ owner: this, button: b, index: i });
490490
}
491491
});
492492
}
493493

494494
if (this.selectedIndexes.indexOf(index) === -1) {
495+
this.selectButton(index);
495496
this.selected.emit(args);
496-
if(!args.cancel){
497-
this.selectButton(index);
498-
}
499497
} else {
500498
if (this.selectionMode !== 'singleRequired') {
499+
this.deselectButton(index);
501500
this.deselected.emit(args);
502-
if(!args.cancel){
503-
this.deselectButton(index);
504-
}
505501
}
506502
}
507503
}
508504
}
509505

510-
export interface IButtonGroupEventArgs extends IBaseEventArgs, CancelableEventArgs {
506+
export interface IButtonGroupEventArgs extends IBaseEventArgs {
511507
owner: IgxButtonGroupComponent;
512508
button: IgxButtonDirective;
513509
index: number;

projects/igniteui-angular/src/lib/buttonGroup/buttongroup.component.spec.ts

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -142,47 +142,6 @@ describe('IgxButtonGroup', () => {
142142
expect(btnGroupInstance.deselected.emit).toHaveBeenCalled();
143143
});
144144

145-
it('should not select the button on click if event is canceled ', () => {
146-
const fixture = TestBed.createComponent(ButtonGroupWithSelectedButtonComponent);
147-
fixture.detectChanges();
148-
149-
const btnGroupInstance = fixture.componentInstance.buttonGroup;
150-
fixture.detectChanges();
151-
152-
btnGroupInstance.buttons[1].select();
153-
fixture.detectChanges();
154-
155-
btnGroupInstance.selected.subscribe((e) => {
156-
e.cancel = true;
157-
});
158-
fixture.detectChanges();
159-
160-
const button = fixture.debugElement.nativeElement.querySelector('button');
161-
button.click();
162-
fixture.detectChanges();
163-
164-
expect(btnGroupInstance.buttons[0].selected).toBe(false);
165-
});
166-
167-
it('should not deselect the button on click if event is canceled ', () => {
168-
const fixture = TestBed.createComponent(ButtonGroupWithSelectedButtonComponent);
169-
fixture.detectChanges();
170-
171-
const btnGroupInstance = fixture.componentInstance.buttonGroup;
172-
fixture.detectChanges();
173-
174-
btnGroupInstance.deselected.subscribe((e) => {
175-
e.cancel = true;
176-
});
177-
fixture.detectChanges();
178-
179-
const button = fixture.debugElement.nativeElement.querySelector('button');
180-
button.click();
181-
fixture.detectChanges();
182-
183-
expect(btnGroupInstance.buttons[0].selected).toBe(true);
184-
});
185-
186145
it('should should reset its current selection state on selectionMode runtime change', () => {
187146
const fixture = TestBed.createComponent(ButtonGroupWithSelectedButtonComponent);
188147
fixture.detectChanges();

0 commit comments

Comments
 (0)