Skip to content

Commit b671522

Browse files
fix(button-group): reverted cancellable on selected and deselected events
1 parent c226e04 commit b671522

File tree

3 files changed

+17
-143
lines changed

3 files changed

+17
-143
lines changed

CHANGELOG.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ All notable changes for each version of this project will be documented in this
1515
- `igniteui-angular` components have improved tree-shaking
1616
- DisplayDensity token and inputs are deprecated in favor of `--ig-size` theming
1717
- We're working on reducing the library size
18-
- IgxRadioComponent has been reduced in half
19-
- IgxSwitchComponent has been reduced in half
18+
- `IgxRadioComponent` size has been reduced in half
19+
- `IgxSwitchComponent` size has been reduced in half
20+
- `IgxRadioComponent`
21+
- **Breaking Change** `IChangeRadioEventArgs` is now `IChangeCheckboxEventArgs`. `ng update` to `17.0.0` will automatically migrate this for you.
22+
- **Breaking Change** `RadioLabelPosition` is now `LabelPosition`. `ng update` to `17.0.0` will automatically migrate this for you.
23+
- `IgxSwitchComponent`
24+
- **Breaking Change** `IChangeSwitchEventArgs` is now `IChangeCheckboxEventArgs`. `ng update` to `17.0.0` will automatically migrate this for you.
25+
- **Breaking Change** `SwitchLabelPosition` is now `LabelPosition`. `ng update` to `17.0.0` will automatically migrate this for you.
2026
- `IgxCombo`
2127
- **Breaking Change** `IComboSelectionChangingEventArgs` properties `newSelection` and `oldSelection` have been renamed to `newValue` and `oldValue` respectively to better reflect their function. Just like Combo's `value`, those will emit either the specified property values or full data items depending on whether `valueKey` is set or not. Automatic migrations are available and will be applied on `ng update`.
2228
- `IComboSelectionChangingEventArgs` exposes two new properties `newSelection` and `oldSelection` in place of the old ones that are no longer affected by `valueKey` and consistently emit items from Combo's `data`.
@@ -28,8 +34,9 @@ All notable changes for each version of this project will be documented in this
2834
- `ISimpleComboSelectionChangingEventArgs` exposes two new properties `newSelection` and `oldSelection` in place of the old ones that are no longer affected by `valueKey` and consistently emit items from Combo's `data`.
2935

3036
Note: In remote data scenarios with `valueKey` set, selected items that are not currently part of the loaded data chunk will be emitted a partial item data object with the `valueKey` property.
31-
- `IgxButtonGroup`:
32-
- Adding cancellable `selecting` and `deselecting` events that are fired before selecting or deselecting a button.
37+
- **Breaking Change** The `value` and `selection` properties now correctly return a single value or data item instead of the same wrapped in array and `undefined` instead of empty array, matching the values emitted from selection event and when working with `formControlName`/`ngModel` directives.
38+
- `IgxCombo`,`IgxSimpleCombo`
39+
- **Breaking Change** The `displayValue` property now returns the display text as expected (instead of display values in array).
3340

3441
## 16.1.5
3542
### General

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

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

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

@@ -238,40 +238,6 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
238238
return this._isVertical ? ButtonGroupAlignment.vertical : ButtonGroupAlignment.horizontal;
239239
}
240240

241-
/**
242-
* An @Ouput property that emits an event before selecting a button.
243-
* ```typescript
244-
* @ViewChild("toast")
245-
* private toast: IgxToastComponent;
246-
* public selectedHandler(buttongroup) {
247-
* this.toast.open()
248-
* }
249-
* ```
250-
* ```html
251-
* <igx-buttongroup #MyChild (selecting)="selectingHandler($event)"></igx-buttongroup>
252-
* <igx-toast #toast>You are currently selecting a button.</igx-toast>
253-
* ```
254-
*/
255-
@Output()
256-
public selecting = new EventEmitter<IButtonGroupCancellableEventArgs>();
257-
258-
/**
259-
* An @Ouput property that emits an event before deselecting a button.
260-
* ```typescript
261-
* @ViewChild("toast")
262-
* private toast: IgxToastComponent;
263-
* public selectedHandler(buttongroup) {
264-
* this.toast.open()
265-
* }
266-
* ```
267-
* ```html
268-
* <igx-buttongroup #MyChild (selecting)="deselectingHandler($event)"></igx-buttongroup>
269-
* <igx-toast #toast>You are currently deselecting a button.</igx-toast>
270-
* ```
271-
*/
272-
@Output()
273-
public deselecting = new EventEmitter<IButtonGroupCancellableEventArgs>();
274-
275241
/**
276242
* An @Ouput property that emits an event when a button is selected.
277243
* ```typescript
@@ -517,30 +483,22 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
517483
public _clickHandler(index: number) {
518484
const button = this.buttons[index];
519485
const args: IButtonGroupEventArgs = { owner: this, button, index };
520-
const cancellableArgs: IButtonGroupCancellableEventArgs = { cancel: false, owner: this, button, index };
521486

522487
if (this.selectionMode !== 'multi') {
523488
this.buttons.forEach((b, i) => {
524489
if (i !== index && this.selectedIndexes.indexOf(i) !== -1) {
525-
this.deselecting.emit({ cancel: false, owner: this, button: b, index: i });
526490
this.deselected.emit({ owner: this, button: b, index: i });
527491
}
528492
});
529493
}
530494

531495
if (this.selectedIndexes.indexOf(index) === -1) {
532-
this.selecting.emit(cancellableArgs);
533-
if (!cancellableArgs.cancel) {
534-
this.selectButton(index);
535-
this.selected.emit(args);
536-
}
496+
this.selectButton(index);
497+
this.selected.emit(args);
537498
} else {
538499
if (this.selectionMode !== 'singleRequired') {
539-
this.deselecting.emit(cancellableArgs);
540-
if (!cancellableArgs.cancel) {
541-
this.deselectButton(index);
542-
this.deselected.emit(args);
543-
}
500+
this.deselectButton(index);
501+
this.deselected.emit(args);
544502
}
545503
}
546504
}
@@ -550,6 +508,4 @@ export interface IButtonGroupEventArgs extends IBaseEventArgs {
550508
owner: IgxButtonGroupComponent;
551509
button: IgxButtonDirective;
552510
index: number;
553-
}
554-
555-
export interface IButtonGroupCancellableEventArgs extends IButtonGroupEventArgs, CancelableEventArgs {}
511+
}

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

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -94,54 +94,6 @@ describe('IgxButtonGroup', () => {
9494
expect(buttongroup.selectedButtons.length).toEqual(0);
9595
});
9696

97-
it('should fire the selecting event when a button is being selected by user interaction, not on initial or programmatic selection', () => {
98-
const fixture = TestBed.createComponent(ButtonGroupWithSelectedButtonComponent);
99-
fixture.detectChanges();
100-
101-
const btnGroupInstance = fixture.componentInstance.buttonGroup;
102-
spyOn(btnGroupInstance.selecting, 'emit');
103-
104-
btnGroupInstance.ngAfterViewInit();
105-
fixture.detectChanges();
106-
107-
expect(btnGroupInstance.selecting.emit).not.toHaveBeenCalled();
108-
109-
btnGroupInstance.buttons[1].select();
110-
fixture.detectChanges();
111-
112-
expect(btnGroupInstance.selecting.emit).not.toHaveBeenCalled();
113-
114-
const button = fixture.debugElement.nativeElement.querySelector('button');
115-
button.click();
116-
117-
expect(btnGroupInstance.selecting.emit).toHaveBeenCalled();
118-
});
119-
120-
it('should fire the deselecting event when a button is being deselected by user interaction, not on programmatic deselection', () => {
121-
const fixture = TestBed.createComponent(ButtonGroupWithSelectedButtonComponent);
122-
fixture.detectChanges();
123-
124-
const btnGroupInstance = fixture.componentInstance.buttonGroup;
125-
btnGroupInstance.buttons[0].select();
126-
btnGroupInstance.buttons[1].select();
127-
spyOn(btnGroupInstance.deselecting, 'emit');
128-
129-
btnGroupInstance.ngAfterViewInit();
130-
fixture.detectChanges();
131-
132-
expect(btnGroupInstance.deselecting.emit).not.toHaveBeenCalled();
133-
134-
btnGroupInstance.buttons[1].deselect();
135-
fixture.detectChanges();
136-
137-
expect(btnGroupInstance.deselecting.emit).not.toHaveBeenCalled();
138-
139-
const button = fixture.debugElement.nativeElement.querySelector('button');
140-
button.click();
141-
142-
expect(btnGroupInstance.deselecting.emit).toHaveBeenCalled();
143-
});
144-
14597
it('should fire the selected event when a button is selected by user interaction, not on initial or programmatic selection', () => {
14698
const fixture = TestBed.createComponent(ButtonGroupWithSelectedButtonComponent);
14799
fixture.detectChanges();
@@ -190,47 +142,6 @@ describe('IgxButtonGroup', () => {
190142
expect(btnGroupInstance.deselected.emit).toHaveBeenCalled();
191143
});
192144

193-
it('should not select the button on click if selecting event is canceled ', () => {
194-
const fixture = TestBed.createComponent(ButtonGroupWithSelectedButtonComponent);
195-
fixture.detectChanges();
196-
197-
const btnGroupInstance = fixture.componentInstance.buttonGroup;
198-
fixture.detectChanges();
199-
200-
btnGroupInstance.buttons[1].select();
201-
fixture.detectChanges();
202-
203-
btnGroupInstance.selecting.subscribe((e) => {
204-
e.cancel = true;
205-
});
206-
fixture.detectChanges();
207-
208-
const button = fixture.debugElement.nativeElement.querySelector('button');
209-
button.click();
210-
fixture.detectChanges();
211-
212-
expect(btnGroupInstance.buttons[0].selected).toBe(false);
213-
});
214-
215-
it('should not deselect the button on click if deselecting event is canceled ', () => {
216-
const fixture = TestBed.createComponent(ButtonGroupWithSelectedButtonComponent);
217-
fixture.detectChanges();
218-
219-
const btnGroupInstance = fixture.componentInstance.buttonGroup;
220-
fixture.detectChanges();
221-
222-
btnGroupInstance.deselecting.subscribe((e) => {
223-
e.cancel = true;
224-
});
225-
fixture.detectChanges();
226-
227-
const button = fixture.debugElement.nativeElement.querySelector('button');
228-
button.click();
229-
fixture.detectChanges();
230-
231-
expect(btnGroupInstance.buttons[0].selected).toBe(true);
232-
});
233-
234145
it('should should reset its current selection state on selectionMode runtime change', () => {
235146
const fixture = TestBed.createComponent(ButtonGroupWithSelectedButtonComponent);
236147
fixture.detectChanges();

0 commit comments

Comments
 (0)