Skip to content

Commit

Permalink
feat(popover): background dismiss, escape dismiss
Browse files Browse the repository at this point in the history
background dismiss, escape dismiss

closes #6817
  • Loading branch information
danbucholtz committed Jun 9, 2016
1 parent 2be96f2 commit 1d78f78
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/components/popover/popover.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {Component, ViewChild, ViewContainerRef, ComponentResolver} from '@angular/core';
import {Renderer, ElementRef} from '@angular/core';
import {Component, ComponentResolver, ElementRef, HostListener, Renderer, ViewChild, ViewContainerRef} from '@angular/core';

import {addSelector} from '../../config/bootstrap';
import {Animation} from '../../animations/animation';
import {Transition, TransitionOptions} from '../../transitions/transition';
import {Config} from '../../config/config';
import {NavParams} from '../nav/nav-params';
import {Platform} from '../../platform/platform';
import {Key} from '../../util/key';
import {isPresent, isUndefined, isDefined} from '../../util/util';
import {nativeRaf, CSS} from '../../util/dom';
import {ViewController} from '../nav/view-controller';
Expand Down Expand Up @@ -204,7 +204,7 @@ class PopoverCmp {
});
}

ionViewDidEnter() {
ngAfterViewInit() {
let activeElement: any = document.activeElement;
if (document.activeElement) {
activeElement.blur();
Expand All @@ -226,6 +226,13 @@ class PopoverCmp {
this.dismiss('backdrop');
}
}

@HostListener('body:keyup', ['$event'])
private _keyUp(ev: KeyboardEvent) {
if (this.enabled && this._viewCtrl.isLast() && ev.keyCode === Key.ESCAPE ) {
this.bdClick();
}
}
}

export interface PopoverOptions {
Expand Down

1 comment on commit 1d78f78

@danbucholtz
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ionViewDidEnter will not get called because the popover/modal sets the instance of dynamically loaded page to the instance attribute on the view-controller. As such, some of the life cycle events for the internal PopoverCmp and ModalCmp don't get called. For now, just use Angular's life cycle events

Please sign in to comment.