Skip to content

Commit efa9951

Browse files
Merge branch '17.2.x' into ganastasov/fix-14324-17.2.x
2 parents 90179c5 + 28c2120 commit efa9951

File tree

7 files changed

+130
-9
lines changed

7 files changed

+130
-9
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,8 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
535535
if (updatedButtons.length > 0) {
536536
updatedButtons.forEach((button) => {
537537
const index = this.buttons.map((b) => b.nativeElement).indexOf(button);
538-
const args: IButtonGroupEventArgs = { owner: this, button: this.buttons[index], index };
539538

540-
this.updateButtonSelectionState(index, args);
539+
this.updateButtonSelectionState(index);
541540
});
542541
}
543542

@@ -562,13 +561,11 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
562561
return updated;
563562
}
564563

565-
private updateButtonSelectionState(index: number, args: IButtonGroupEventArgs) {
564+
private updateButtonSelectionState(index: number) {
566565
if (this.buttons[index].selected) {
567566
this.updateSelected(index);
568-
this.selected.emit(args);
569567
} else {
570568
this.updateDeselected(index);
571-
this.deselected.emit(args);
572569
}
573570
}
574571
}

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,32 @@ describe('IgxButtonGroup', () => {
465465
expect(buttonGroup.buttons[0].nativeElement.classList.contains('igx-button-group__item--selected')).toBe(false);
466466
});
467467

468+
it('should emit selected event only once per selection', async() => {
469+
const fixture = TestBed.createComponent(InitButtonGroupComponent);
470+
fixture.detectChanges();
471+
await wait();
472+
473+
const buttonGroup = fixture.componentInstance.buttonGroup;
474+
475+
spyOn(buttonGroup.selected, 'emit').and.callThrough();
476+
477+
buttonGroup.selectButton(0);
478+
await wait();
479+
fixture.detectChanges();
480+
481+
const buttons = fixture.nativeElement.querySelectorAll('button');
482+
buttons[1].click();
483+
await wait();
484+
fixture.detectChanges();
485+
486+
expect(buttonGroup.selected.emit).toHaveBeenCalledTimes(1);
487+
488+
buttons[0].click();
489+
await wait();
490+
fixture.detectChanges();
491+
492+
expect(buttonGroup.selected.emit).toHaveBeenCalledTimes(2);
493+
});
468494
});
469495

470496
@Component({

projects/igniteui-angular/src/lib/drop-down/drop-down.component.spec.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { DisplayDensity } from '../core/density';
1818
import { IgxSelectionAPIService } from '../core/selection';
1919
import { IgxButtonDirective } from '../directives/button/button.directive';
2020
import { NgFor } from '@angular/common';
21+
import { ConnectedPositioningStrategy, HorizontalAlignment, OverlaySettings, VerticalAlignment } from '../services/public_api';
2122

2223
const CSS_CLASS_DROP_DOWN_BASE = 'igx-drop-down';
2324
const CSS_CLASS_LIST = 'igx-drop-down__list';
@@ -242,6 +243,57 @@ describe('IgxDropDown ', () => {
242243
expect(dropdown.opening.emit).toHaveBeenCalledTimes(1);
243244
expect(dropdown.opened.emit).toHaveBeenCalledTimes(1);
244245
}));
246+
it('should use default overlay settings if none are provided', () => {
247+
const toggle: IgxToggleDirective = (dropdown as any).toggleDirective;
248+
249+
spyOn(toggle, 'open').and.callThrough();
250+
251+
dropdown.open();
252+
fixture.detectChanges();
253+
expect(toggle.open).toHaveBeenCalledTimes(1);
254+
255+
const appliedSettings = (toggle.open as jasmine.Spy).calls.mostRecent().args[0];
256+
expect(appliedSettings.closeOnOutsideClick).toBe(true);
257+
expect(appliedSettings.modal).toBe(false);
258+
expect(appliedSettings.positionStrategy instanceof ConnectedPositioningStrategy).toBe(true);
259+
260+
const positionStrategy = appliedSettings.positionStrategy as ConnectedPositioningStrategy;
261+
expect(positionStrategy.settings.horizontalStartPoint).toBe(HorizontalAlignment.Left);
262+
expect(positionStrategy.settings.verticalStartPoint).toBe(VerticalAlignment.Bottom);
263+
expect(positionStrategy.settings.horizontalDirection).toBe(HorizontalAlignment.Right);
264+
expect(positionStrategy.settings.verticalDirection).toBe(VerticalAlignment.Bottom);
265+
});
266+
267+
it('should apply custom overlay settings if provided', () => {
268+
const toggle: IgxToggleDirective = (dropdown as any).toggleDirective;
269+
const customOverlaySettings: OverlaySettings = {
270+
closeOnOutsideClick: false,
271+
modal: true,
272+
positionStrategy: new ConnectedPositioningStrategy({
273+
horizontalStartPoint: HorizontalAlignment.Right,
274+
verticalStartPoint: VerticalAlignment.Top,
275+
horizontalDirection: HorizontalAlignment.Left,
276+
verticalDirection: VerticalAlignment.Top
277+
})
278+
};
279+
280+
spyOn(toggle, 'open').and.callThrough();
281+
282+
dropdown.open(customOverlaySettings);
283+
fixture.detectChanges();
284+
expect(toggle.open).toHaveBeenCalledTimes(1);
285+
286+
const appliedSettings = (toggle.open as jasmine.Spy).calls.mostRecent().args[0];
287+
expect(appliedSettings.closeOnOutsideClick).toBe(customOverlaySettings.closeOnOutsideClick);
288+
expect(appliedSettings.modal).toBe(customOverlaySettings.modal);
289+
expect(appliedSettings.positionStrategy instanceof ConnectedPositioningStrategy).toBe(true);
290+
291+
const positionStrategy = appliedSettings.positionStrategy as ConnectedPositioningStrategy;
292+
expect(positionStrategy.settings.horizontalStartPoint).toBe(HorizontalAlignment.Right);
293+
expect(positionStrategy.settings.verticalStartPoint).toBe(VerticalAlignment.Top);
294+
expect(positionStrategy.settings.horizontalDirection).toBe(HorizontalAlignment.Left);
295+
expect(positionStrategy.settings.verticalDirection).toBe(VerticalAlignment.Top);
296+
});
245297
it('#2798 - should allow canceling of open/close through opening/closing events', fakeAsync(() => {
246298
const toggle: IgxToggleDirective = (dropdown as any).toggleDirective;
247299
const onOpeningSpy = spyOn(dropdown.opening, 'emit').and.callThrough();

projects/igniteui-angular/src/lib/drop-down/drop-down.component.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ import { IgxDropDownItemBaseDirective } from './drop-down-item.base';
3131
import { IgxForOfToken } from '../directives/for-of/for_of.directive';
3232
import { take } from 'rxjs/operators';
3333
import { DisplayDensityToken, IDisplayDensityOptions } from '../core/density';
34-
import { OverlaySettings } from '../services/overlay/utilities';
34+
import { OverlaySettings } from '../services/overlay/utilities';
3535
import { NgIf } from '@angular/common';
36+
import { ConnectedPositioningStrategy } from '../services/public_api';
3637

3738
/**
3839
* **Ignite UI for Angular DropDown** -
@@ -50,6 +51,7 @@ import { NgIf } from '@angular/common';
5051
* </igx-drop-down>
5152
* ```
5253
*/
54+
5355
@Component({
5456
selector: 'igx-drop-down',
5557
templateUrl: './drop-down.component.html',
@@ -244,10 +246,22 @@ export class IgxDropDownComponent extends IgxDropDownBaseDirective implements ID
244246
* ```
245247
*/
246248
public open(overlaySettings?: OverlaySettings) {
247-
this.toggleDirective.open(overlaySettings);
249+
const settings = overlaySettings || this.getDefaultOverlaySettings();
250+
this.toggleDirective.open(settings);
248251
this.updateScrollPosition();
249252
}
250253

254+
/**
255+
* @hidden @internal
256+
*/
257+
public getDefaultOverlaySettings(): OverlaySettings {
258+
return {
259+
closeOnOutsideClick: true,
260+
modal: false,
261+
positionStrategy: new ConnectedPositioningStrategy()
262+
};
263+
}
264+
251265
/**
252266
* Closes the dropdown
253267
*

projects/igniteui-angular/src/lib/grids/grid/grid-filtering-ui.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2747,6 +2747,30 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
27472747
filterUIRow = fix.debugElement.query(By.css(FILTER_UI_ROW));
27482748
expect(filterUIRow).toBeNull('Default filter template was found on a column with custom filtering.');
27492749
}));
2750+
2751+
it('Should not prevent mousedown event when target is within the filter cell template', fakeAsync(() => {
2752+
const filterCell = GridFunctions.getFilterCell(fix, 'ProductName');
2753+
const input = filterCell.query(By.css('input')).nativeElement;
2754+
2755+
const mousedownEvent = new MouseEvent('mousedown', { bubbles: true });
2756+
const preventDefaultSpy = spyOn(mousedownEvent, 'preventDefault');
2757+
input.dispatchEvent(mousedownEvent, { bubbles: true });
2758+
fix.detectChanges();
2759+
2760+
expect(preventDefaultSpy).not.toHaveBeenCalled();
2761+
}));
2762+
2763+
it('Should prevent mousedown event when target is filter cell or its parent elements', fakeAsync(() => {
2764+
const filteringCells = fix.debugElement.queryAll(By.css(FILTER_UI_CELL));
2765+
const firstCell = filteringCells[0].nativeElement;
2766+
2767+
const mousedownEvent = new MouseEvent('mousedown', { bubbles: true });
2768+
const preventDefaultSpy = spyOn(mousedownEvent, 'preventDefault');
2769+
firstCell.dispatchEvent(mousedownEvent);
2770+
fix.detectChanges();
2771+
2772+
expect(preventDefaultSpy).toHaveBeenCalled();
2773+
}));
27502774
});
27512775

27522776
describe(null, () => {
@@ -2823,6 +2847,7 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
28232847

28242848
expect(grid.rowList.length).toEqual(1);
28252849
}));
2850+
28262851
});
28272852

28282853
describe('Filtering events', () => {

projects/igniteui-angular/src/lib/grids/headers/grid-header-group.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,12 @@ export class IgxGridHeaderGroupComponent implements DoCheck {
262262
*/
263263
@HostListener('mousedown', ['$event'])
264264
public onMouseDown(event: MouseEvent): void {
265-
// hack for preventing text selection in IE and Edge while dragging the resize element
266-
event.preventDefault();
265+
if (!this.grid.allowFiltering ||
266+
(event.composedPath().findIndex(el =>
267+
(el as Element).tagName?.toLowerCase() === 'igx-grid-filtering-cell') < 1)) {
268+
// Hack for preventing text selection in IE and Edge while dragging the resize element
269+
event.preventDefault();
270+
}
267271
}
268272

269273
/**

projects/igniteui-angular/src/lib/grids/toolbar/grid-toolbar-advanced-filtering.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ export class IgxGridToolbarAdvancedFilteringComponent implements AfterViewInit {
4949
});
5050
}
5151

52+
/**
53+
* @hidden
54+
*/
5255
public ngAfterViewInit(): void {
5356
this.numberOfColumns = this.grid?.advancedFilteringExpressionsTree ? this.extractUniqueFieldNamesFromFilterTree(this.grid?.advancedFilteringExpressionsTree).length : 0;
5457
}

0 commit comments

Comments
 (0)