Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(modal): don't close modal on ESC if file dialog is open #3455

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/modal/modal-window.spec.ts
Expand Up @@ -107,7 +107,7 @@ describe('ngb-modal-dialog', () => {
done();
});

fixture.nativeElement.dispatchEvent(createKeyEvent(Key.Escape));
fixture.nativeElement.dispatchEvent(createKeyEvent(Key.Escape, {type: 'keydown'}));
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/modal/modal-window.ts
Expand Up @@ -55,7 +55,7 @@ export class NgbModalWindow implements OnInit,
constructor(
@Inject(DOCUMENT) private _document: any, private _elRef: ElementRef<HTMLElement>, private _zone: NgZone) {
_zone.runOutsideAngular(() => {
fromEvent<KeyboardEvent>(this._elRef.nativeElement, 'keyup')
fromEvent<KeyboardEvent>(this._elRef.nativeElement, 'keydown')
.pipe(
takeUntil(this.dismissEvent),
// tslint:disable-next-line:deprecation
Expand Down
8 changes: 4 additions & 4 deletions src/modal/modal.spec.ts
Expand Up @@ -353,13 +353,13 @@ describe('ngb-modal', () => {
expect(fixture.nativeElement).toHaveModal(['foo', 'bar']);
expect(document.activeElement).toBe(ngbModalWindow2);

ngbModalWindow2.dispatchEvent(createKeyEvent(Key.Escape));
ngbModalWindow2.dispatchEvent(createKeyEvent(Key.Escape, {type: 'keydown'}));
tick(16); // RAF in escape handling
fixture.detectChanges();
expect(fixture.nativeElement).toHaveModal(['foo']);
expect(document.activeElement).toBe(ngbModalWindow1);

ngbModalWindow1.dispatchEvent(createKeyEvent(Key.Escape));
ngbModalWindow1.dispatchEvent(createKeyEvent(Key.Escape, {type: 'keydown'}));
tick(16); // RAF in escape handling
fixture.detectChanges();
expect(fixture.nativeElement).not.toHaveModal();
Expand Down Expand Up @@ -580,7 +580,7 @@ describe('ngb-modal', () => {
fixture.detectChanges();
expect(fixture.nativeElement).toHaveModal('foo');

document.querySelector('ngb-modal-window').dispatchEvent(createKeyEvent(Key.Escape));
document.querySelector('ngb-modal-window').dispatchEvent(createKeyEvent(Key.Escape, {type: 'keydown'}));
tick(16); // RAF in escape handling
fixture.detectChanges();
expect(fixture.nativeElement).not.toHaveModal();
Expand All @@ -591,7 +591,7 @@ describe('ngb-modal', () => {
fixture.detectChanges();
expect(fixture.nativeElement).toHaveModal('foo');

document.querySelector('ngb-modal-window').dispatchEvent(createKeyEvent(Key.Escape));
document.querySelector('ngb-modal-window').dispatchEvent(createKeyEvent(Key.Escape, {type: 'keydown'}));
tick(16); // RAF in escape handling
fixture.detectChanges();
expect(fixture.nativeElement).toHaveModal();
Expand Down
2 changes: 1 addition & 1 deletion src/util/autoclose.ts
Expand Up @@ -39,7 +39,7 @@ export function ngbAutoClose(
}
};

const escapes$ = fromEvent<KeyboardEvent>(document, 'keyup')
const escapes$ = fromEvent<KeyboardEvent>(document, 'keydown')
maxokorokov marked this conversation as resolved.
Show resolved Hide resolved
.pipe(
takeUntil(closed$),
// tslint:disable-next-line:deprecation
Expand Down