Skip to content

Commit 0c081f8

Browse files
committed
chore(overlay): Address comments #8148
1 parent 1550008 commit 0c081f8

File tree

5 files changed

+38
-35
lines changed

5 files changed

+38
-35
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,7 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
185185
private _remoteSelection = {};
186186
private _onChangeCallback: (_: any) => void = noop;
187187
private _onTouchedCallback: () => void = noop;
188-
private _overlaySettings: OverlaySettings = {
189-
scrollStrategy: new AbsoluteScrollStrategy(),
190-
positionStrategy: new AutoPositionStrategy(),
191-
modal: false,
192-
closeOnOutsideClick: true,
193-
excludeFromOutsideClick: [this.elementRef.nativeElement as HTMLElement]
194-
};
188+
private _overlaySettings: OverlaySettings;
195189
private _value = '';
196190
private _valid = IgxComboState.INITIAL;
197191
constructor(
@@ -1228,7 +1222,15 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
12281222
*/
12291223
public ngOnInit() {
12301224
this.ngControl = this._injector.get<NgControl>(NgControl, null);
1231-
this._overlaySettings.target = this.elementRef.nativeElement;
1225+
const targetElement = this.elementRef.nativeElement;
1226+
this._overlaySettings = {
1227+
target: targetElement,
1228+
scrollStrategy: new AbsoluteScrollStrategy(),
1229+
positionStrategy: new AutoPositionStrategy(),
1230+
modal: false,
1231+
closeOnOutsideClick: true,
1232+
excludeFromOutsideClick: [targetElement as HTMLElement]
1233+
};
12321234
this.selection.set(this.id, new Set());
12331235
this._iconService.addSvgIconFromText(caseSensitiveIcon.name, caseSensitiveIcon.value, 'case-sensitive');
12341236
}

projects/igniteui-angular/src/lib/directives/autocomplete/autocomplete.directive.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
Optional,
1313
Output,
1414
Self,
15-
AfterViewInit
15+
AfterViewInit,
16+
OnInit
1617
} from '@angular/core';
1718
import { NgModel, FormControlName } from '@angular/forms';
1819
import { CommonModule } from '@angular/common';
@@ -75,7 +76,7 @@ export interface AutocompleteOverlaySettings {
7576
@Directive({
7677
selector: '[igxAutocomplete]'
7778
})
78-
export class IgxAutocompleteDirective extends IgxDropDownItemNavigationDirective implements OnDestroy, AfterViewInit {
79+
export class IgxAutocompleteDirective extends IgxDropDownItemNavigationDirective implements OnDestroy, AfterViewInit, OnInit {
7980

8081
private _shouldBeOpen = false;
8182
constructor(@Self() @Optional() @Inject(NgModel) protected ngModel: NgModel,
@@ -87,13 +88,7 @@ export class IgxAutocompleteDirective extends IgxDropDownItemNavigationDirective
8788
}
8889
private destroy$ = new Subject();
8990

90-
private defaultSettings: OverlaySettings = {
91-
target: this.parentElement,
92-
modal: false,
93-
scrollStrategy: new AbsoluteScrollStrategy(),
94-
positionStrategy: new AutoPositionStrategy(),
95-
excludeFromOutsideClick: [this.parentElement]
96-
};
91+
private defaultSettings: OverlaySettings;
9792

9893
protected id: string;
9994
protected get model() {
@@ -348,6 +343,18 @@ export class IgxAutocompleteDirective extends IgxDropDownItemNavigationDirective
348343
this.cdr.detectChanges();
349344
}
350345

346+
/** @hidden @internal */
347+
public ngOnInit() {
348+
const targetElement = this.parentElement;
349+
this.defaultSettings = {
350+
target: targetElement,
351+
modal: false,
352+
scrollStrategy: new AbsoluteScrollStrategy(),
353+
positionStrategy: new AutoPositionStrategy(),
354+
excludeFromOutsideClick: [targetElement]
355+
};
356+
}
357+
351358
/** @hidden */
352359
public ngOnDestroy() {
353360
this.destroy$.next();

projects/igniteui-angular/src/lib/directives/toggle/toggle.directive.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,13 +434,14 @@ export class IgxToggleActionDirective implements OnInit {
434434
* @hidden
435435
*/
436436
public ngOnInit() {
437+
const targetElement = this.element.nativeElement;
437438
this._overlayDefaults = {
438-
target: this.element.nativeElement,
439+
target: targetElement,
439440
positionStrategy: new ConnectedPositioningStrategy(),
440441
scrollStrategy: new AbsoluteScrollStrategy(),
441442
closeOnOutsideClick: true,
442443
modal: false,
443-
excludeFromOutsideClick: [this.element.nativeElement as HTMLElement]
444+
excludeFromOutsideClick: [targetElement as HTMLElement]
444445
};
445446
}
446447

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,6 @@ export class IgxSelectComponent extends IgxDropDownComponent implements IgxSelec
492492
const args: CancelableEventArgs = { cancel: event.cancel };
493493
this.onClosing.emit(args);
494494
event.cancel = args.cancel;
495-
if (args.cancel) {
496-
return;
497-
}
498495
}
499496

500497
/** @hidden @internal */

projects/igniteui-angular/src/lib/services/overlay/overlay.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -651,20 +651,16 @@ export class IgxOverlayService implements OnDestroy {
651651
}
652652
if (info.settings.closeOnOutsideClick) {
653653
const target = ev.target as any;
654-
// if the click is on the element do not close this overlay
655-
if (!info.elementRef.nativeElement.contains(target)) {
656-
// if we should exclude position target check if the click is over it. If so do not close overlay
657-
const excludeElements = info.settings.excludeFromOutsideClick ? [...info.settings.excludeFromOutsideClick] : [];
658-
const isInsideClick: boolean = excludeElements.some(e => e.contains(target as Node));
659-
if (!isInsideClick) {
660-
// if the click is outside click, but close animation has started do nothing
661-
if (!(info.closeAnimationPlayer && info.closeAnimationPlayer.hasStarted())) {
662-
this._hide(info.id, ev);
663-
}
664-
}
665-
} else {
666-
// TODO: should we return here, or continue with next overlays
654+
const overlayElement = info.elementRef.nativeElement;
655+
// check if the click is on the overlay element or on an element from the exclusion list, and if so do not close the overlay
656+
const excludeElements = info.settings.excludeFromOutsideClick ?
657+
[...info.settings.excludeFromOutsideClick, overlayElement] : [overlayElement];
658+
const isInsideClick: boolean = excludeElements.some(e => e.contains(target as Node));
659+
if (isInsideClick) {
667660
return;
661+
// if the click is outside click, but close animation has started do nothing
662+
} else if (!(info.closeAnimationPlayer && info.closeAnimationPlayer.hasStarted())) {
663+
this._hide(info.id, ev);
668664
}
669665
}
670666
}

0 commit comments

Comments
 (0)