Skip to content

Commit 72e3a96

Browse files
Merge pull request #14457 from IgniteUI/ikitanov/fix-#14297-18.0.x
Adding default overlay settings - 18.0.x
2 parents a2c706e + 139f8e2 commit 72e3a96

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

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
@@ -17,6 +17,7 @@ import { IgxDropDownItemBaseDirective } from './drop-down-item.base';
1717
import { IgxSelectionAPIService } from '../core/selection';
1818
import { IgxButtonDirective } from '../directives/button/button.directive';
1919
import { NgFor } from '@angular/common';
20+
import { ConnectedPositioningStrategy, HorizontalAlignment, OverlaySettings, VerticalAlignment } from '../services/public_api';
2021

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

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { IgxForOfToken } from '../directives/for-of/for_of.directive';
3131
import { take } from 'rxjs/operators';
3232
import { OverlaySettings } from '../services/overlay/utilities';
3333
import { DOCUMENT, NgIf } from '@angular/common';
34+
import { ConnectedPositioningStrategy } from '../services/overlay/position';
3435

3536
/**
3637
* **Ignite UI for Angular DropDown** -
@@ -48,6 +49,7 @@ import { DOCUMENT, NgIf } from '@angular/common';
4849
* </igx-drop-down>
4950
* ```
5051
*/
52+
5153
@Component({
5254
selector: 'igx-drop-down',
5355
templateUrl: './drop-down.component.html',
@@ -242,10 +244,22 @@ export class IgxDropDownComponent extends IgxDropDownBaseDirective implements ID
242244
* ```
243245
*/
244246
public open(overlaySettings?: OverlaySettings) {
245-
this.toggleDirective.open(overlaySettings);
247+
const settings = overlaySettings || this.getDefaultOverlaySettings();
248+
this.toggleDirective.open(settings);
246249
this.updateScrollPosition();
247250
}
248251

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

0 commit comments

Comments
 (0)