Skip to content

Commit a22f0de

Browse files
Adding default overlay settings - 17.2.x (#14458)
* fix(dropdown): Adding default overlay settings * chore(dropdown): Addressing comments and removing unnecessary code and imports --------- Co-authored-by: Teodosia Hristodorova <[email protected]>
1 parent 7934c21 commit a22f0de

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
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
@@ -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
*

0 commit comments

Comments
 (0)