Skip to content

Commit 761bccc

Browse files
committed
refactor(overlay): address PR comments
1 parent 6c01d41 commit 761bccc

File tree

6 files changed

+65
-47
lines changed

6 files changed

+65
-47
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ All notable changes for each version of this project will be documented in this
88
- `igxCombo`
99
- **Behavioral Change** - Change default positioning strategy from `ConnectedPositioningStrategy` to `AutoPositionStrategy`. The [`Auto`](https://www.infragistics.com/products/ignite-ui-angular/angular/components/overlay_position.html#auto) strategy will initially try to show the element like the Connected strategy does. If the element goes out of the viewport Auto will flip the starting point and the direction, i.e. if the direction is 'bottom', it will switch it to 'top' and so on. If after flipping direction the content goes out of the view, auto strategy will revert to initial start point and direction and will push the content into the view. Note after pushing the content it may hide the combo's input.
1010
- `IgxOverlay`
11-
- **Behavioral Change** - Added new property `closeOnEsc` in `OverlaySettings`. Should overlay close or not on escape keypress can now be controlled via this new property. By default `closeOnEsc` is set to `false`.
11+
- **Behavioral Change** - Added new property `closeOnEscape` in `OverlaySettings`. Should overlay close or not on escape keypress can now be controlled via this new property. By default `closeOnEscape` is set to `false`.
1212
- `igxDialog`
13-
- Added `closeOnEscapeKey` - with it, the dialog can be allowed or prevented from closing when `Esc` is pressed.
13+
- Added `closeOnEscape` - with it, the dialog can be allowed or prevented from closing when `Esc` is pressed.
1414
- `IgxNavbar`:
1515
- **Breaking Changes** - The `igx-action-icon` has been renamed to `igx-navbar-action`. It should get renamed in your components via `ng update`;
1616
- `igxGrid`

projects/igniteui-angular/src/lib/date-picker/date-picker.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
784784
this._modalOverlaySettings = {
785785
closeOnOutsideClick: true,
786786
modal: true,
787-
closeOnEsc: true,
787+
closeOnEscape: true,
788788
outlet: this.outlet
789789
};
790790

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,36 @@ export class IgxDialogComponent implements IToggleView, OnInit, OnDestroy, After
7373
@Input()
7474
public id = `igx-dialog-${DIALOG_ID++}`;
7575

76+
/**
77+
* Controls whether the dialog should be shown as modal. Defaults to `true`
78+
* ```html
79+
* <igx-dialog [isModal]="false" ></igx-dialog>
80+
* ```
81+
*/
7682
@Input()
77-
get isModal() {
83+
public get isModal() {
7884
return this._isModal;
7985
}
8086

81-
set isModal(val: boolean) {
87+
public set isModal(val: boolean) {
8288
this._overlayDefaultSettings.modal = val;
8389
this._isModal = val;
8490
}
8591

92+
/**
93+
* Controls whether the dialog should close when `Esc` key is pressed. Defaults to `true`
94+
* ```html
95+
* <igx-dialog [closeOnEscape]="false" ></igx-dialog>
96+
* ```
97+
*/
8698
@Input()
87-
get closeOnEscapeKey() {
88-
return this._closeOnEscapeKey;
99+
public get closeOnEscape() {
100+
return this._closeOnEscape;
89101
}
90102

91-
set closeOnEscapeKey(val: boolean) {
92-
this._overlayDefaultSettings.closeOnEsc = val;
93-
this._closeOnEscapeKey = val;
103+
public set closeOnEscape(val: boolean) {
104+
this._overlayDefaultSettings.closeOnEscape = val;
105+
this._closeOnEscape = val;
94106
}
95107

96108
/**
@@ -311,7 +323,7 @@ export class IgxDialogComponent implements IToggleView, OnInit, OnDestroy, After
311323

312324
private _overlayDefaultSettings: OverlaySettings;
313325
private _closeOnOutsideSelect = false;
314-
private _closeOnEscapeKey = true;
326+
private _closeOnEscape = true;
315327
private _isModal = true;
316328
protected destroy$ = new Subject<boolean>();
317329

@@ -415,7 +427,7 @@ export class IgxDialogComponent implements IToggleView, OnInit, OnDestroy, After
415427
positionStrategy: new GlobalPositionStrategy(this._positionSettings),
416428
scrollStrategy: new NoOpScrollStrategy(),
417429
modal: this.isModal,
418-
closeOnEsc: this._closeOnEscapeKey,
430+
closeOnEscape: this._closeOnEscape,
419431
closeOnOutsideClick: this.closeOnOutsideSelect
420432
};
421433
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,7 +2718,7 @@ describe('igxOverlay', () => {
27182718
const fixture = TestBed.createComponent(EmptyPageComponent);
27192719
const overlay = fixture.componentInstance.overlay;
27202720
const overlaySettings: OverlaySettings = {
2721-
closeOnEsc: true,
2721+
closeOnEscape: true,
27222722
};
27232723

27242724
overlay.show(overlay.attach(SimpleDynamicComponent), overlaySettings);
@@ -2738,7 +2738,7 @@ describe('igxOverlay', () => {
27382738
const fixture = TestBed.createComponent(EmptyPageComponent);
27392739
const overlay = fixture.componentInstance.overlay;
27402740
const overlaySettings: OverlaySettings = {
2741-
closeOnEsc: false
2741+
closeOnEscape: false
27422742
};
27432743

27442744
overlay.show(overlay.attach(SimpleDynamicComponent), overlaySettings);
@@ -2757,9 +2757,9 @@ describe('igxOverlay', () => {
27572757
it('Should close the opened overlays consecutively on esc keypress', fakeAsync(() => {
27582758
const fixture = TestBed.createComponent(EmptyPageComponent);
27592759
const overlay = fixture.componentInstance.overlay;
2760-
overlay.show(overlay.attach(SimpleDynamicComponent), { closeOnEsc: true });
2760+
overlay.show(overlay.attach(SimpleDynamicComponent), { closeOnEscape: true });
27612761
tick();
2762-
overlay.show(overlay.attach(SimpleDynamicComponent), { closeOnEsc: true });
2762+
overlay.show(overlay.attach(SimpleDynamicComponent), { closeOnEscape: true });
27632763
tick();
27642764

27652765
const overlayDiv = document.getElementsByClassName(CLASS_OVERLAY_MAIN)[0];
@@ -2777,11 +2777,11 @@ describe('igxOverlay', () => {
27772777
it('Should not close the opened overlays consecutively on esc keypress', fakeAsync(() => {
27782778
const fixture = TestBed.createComponent(EmptyPageComponent);
27792779
const overlay = fixture.componentInstance.overlay;
2780-
overlay.show(overlay.attach(SimpleDynamicComponent), { closeOnEsc: true });
2780+
overlay.show(overlay.attach(SimpleDynamicComponent), { closeOnEscape: true });
27812781
tick();
2782-
overlay.show(overlay.attach(SimpleDynamicComponent), { closeOnEsc: false });
2782+
overlay.show(overlay.attach(SimpleDynamicComponent), { closeOnEscape: false });
27832783
tick();
2784-
overlay.show(overlay.attach(SimpleDynamicComponent), { closeOnEsc: true });
2784+
overlay.show(overlay.attach(SimpleDynamicComponent), { closeOnEscape: true });
27852785
tick();
27862786

27872787
const overlayDiv = document.getElementsByClassName(CLASS_OVERLAY_MAIN)[0];
@@ -2801,7 +2801,7 @@ describe('igxOverlay', () => {
28012801
const fixture = TestBed.createComponent(EmptyPageComponent);
28022802
const overlay = fixture.componentInstance.overlay;
28032803
const overlaySettings: OverlaySettings = {
2804-
closeOnEsc: true,
2804+
closeOnEscape: true,
28052805
};
28062806

28072807
overlay.show(overlay.attach(SimpleDynamicComponent), overlaySettings);

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

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1+
import { AnimationAnimateRefMetadata, AnimationBuilder, AnimationMetadataType, AnimationReferenceMetadata } from '@angular/animations';
12
import { DOCUMENT } from '@angular/common';
2-
import { GlobalPositionStrategy } from './position/global-position-strategy';
3-
import { NoOpScrollStrategy } from './scroll/NoOpScrollStrategy';
4-
import {
5-
OverlaySettings,
6-
OverlayEventArgs,
7-
OverlayInfo,
8-
OverlayAnimationEventArgs,
9-
OverlayCancelableEventArgs,
10-
OverlayClosingEventArgs
11-
} from './utilities';
12-
133
import {
144
ApplicationRef,
155
ComponentFactory,
@@ -20,17 +10,22 @@ import {
2010
Inject,
2111
Injectable,
2212
Injector,
23-
Type,
24-
OnDestroy,
2513
NgModuleRef,
26-
NgZone
14+
NgZone, OnDestroy, Type
2715
} from '@angular/core';
28-
import { AnimationBuilder, AnimationReferenceMetadata, AnimationMetadataType, AnimationAnimateRefMetadata } from '@angular/animations';
29-
import { fromEvent, Subject } from 'rxjs';
16+
import { fromEvent, Subject, Subscription } from 'rxjs';
3017
import { filter, takeUntil } from 'rxjs/operators';
3118
import { IAnimationParams } from '../../animations/main';
3219
import { showMessage } from '../../core/deprecateDecorators';
33-
import { FromEventTarget } from 'rxjs/internal/observable/fromEvent';
20+
import { GlobalPositionStrategy } from './position/global-position-strategy';
21+
import { NoOpScrollStrategy } from './scroll/NoOpScrollStrategy';
22+
import {
23+
OverlayAnimationEventArgs,
24+
OverlayCancelableEventArgs,
25+
OverlayClosingEventArgs, OverlayEventArgs,
26+
OverlayInfo, OverlaySettings
27+
} from './utilities';
28+
3429

3530
let warningShown = false;
3631

@@ -44,14 +39,15 @@ export class IgxOverlayService implements OnDestroy {
4439
private _overlayInfos: OverlayInfo[] = [];
4540
private _overlayElement: HTMLElement;
4641
private _document: Document;
42+
private _keyPressEventListener: Subscription;
4743
private destroy$ = new Subject<boolean>();
4844

4945
private _defaultSettings: OverlaySettings = {
5046
positionStrategy: new GlobalPositionStrategy(),
5147
scrollStrategy: new NoOpScrollStrategy(),
5248
modal: true,
5349
closeOnOutsideClick: true,
54-
closeOnEsc: false
50+
closeOnEscape: false
5551
};
5652

5753
/**
@@ -322,7 +318,7 @@ export class IgxOverlayService implements OnDestroy {
322318
}
323319

324320
this.addOutsideClickListener(info);
325-
this.addResizeHandler(info.id);
321+
this.addResizeHandler();
326322
this.addCloseOnEscapeListener();
327323

328324
if (info.settings.modal) {
@@ -359,7 +355,8 @@ export class IgxOverlayService implements OnDestroy {
359355
// TODO: synchronize where these are added/attached and where removed/detached
360356
info.settings.scrollStrategy.detach();
361357
this.removeOutsideClickListener(info);
362-
this.removeResizeHandler(info.id);
358+
this.removeResizeHandler();
359+
this.removeCloseOnEscapeListener();
363360

364361
const child: HTMLElement = info.elementRef.nativeElement;
365362
if (info.settings.modal) {
@@ -706,7 +703,7 @@ export class IgxOverlayService implements OnDestroy {
706703
}
707704
}
708705

709-
private addResizeHandler(id: string) {
706+
private addResizeHandler() {
710707
const closingOverlaysCount =
711708
this._overlayInfos
712709
.filter(o => o.closeAnimationPlayer && o.closeAnimationPlayer.hasStarted())
@@ -716,7 +713,7 @@ export class IgxOverlayService implements OnDestroy {
716713
}
717714
}
718715

719-
private removeResizeHandler(id: string) {
716+
private removeResizeHandler() {
720717
const closingOverlaysCount =
721718
this._overlayInfos
722719
.filter(o => o.closeAnimationPlayer && o.closeAnimationPlayer.hasStarted())
@@ -730,18 +727,27 @@ export class IgxOverlayService implements OnDestroy {
730727
// if all overlays minus closing overlays equals one add the handler
731728
if (this._overlayInfos.length - this._overlayInfos.filter(x => x.closeAnimationPlayer
732729
&& x.closeAnimationPlayer.hasStarted()).length === 1) {
733-
fromEvent(this._document, 'keydown').pipe(
734-
filter((ev: KeyboardEvent) => ev.key === 'Escape' || ev.key === 'Esc'),
735-
takeUntil(this.destroy$)
730+
this._keyPressEventListener = fromEvent(this._document, 'keydown').pipe(
731+
filter((ev: KeyboardEvent) => ev.key === 'Escape' || ev.key === 'Esc')
736732
).subscribe(() => {
737733
const targetOverlay = this._overlayInfos[this._overlayInfos.length - 1];
738-
if (targetOverlay.settings.closeOnEsc) {
734+
if (targetOverlay.settings.closeOnEscape) {
739735
this.hide(targetOverlay.id);
740736
}
741737
});
742738
}
743739
}
744740

741+
private removeCloseOnEscapeListener() {
742+
const closingOverlaysCount =
743+
this._overlayInfos
744+
.filter(o => o.closeAnimationPlayer && o.closeAnimationPlayer.hasStarted())
745+
.length;
746+
if (this._overlayInfos.length - closingOverlaysCount === 1 && !this._keyPressEventListener.closed) {
747+
this._keyPressEventListener.unsubscribe();
748+
}
749+
}
750+
745751
/** @hidden */
746752
public repositionAll = () => {
747753
for (let i = this._overlayInfos.length; i--;) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export interface OverlaySettings {
5959
/** Set if the overlay should close on outside click */
6060
closeOnOutsideClick?: boolean;
6161
/** Set if the overlay should close when `Esc` key is pressed */
62-
closeOnEsc?: boolean;
62+
closeOnEscape?: boolean;
6363
/** Set the outlet container to attach the overlay to */
6464
outlet?: IgxOverlayOutletDirective | ElementRef;
6565
/**

0 commit comments

Comments
 (0)