|
1 |
| -import {Component, Renderer, ElementRef} from 'angular2/core'; |
| 1 | +import {Component, Renderer, ElementRef, HostListener} from 'angular2/core'; |
2 | 2 | import {NgFor, NgIf} from 'angular2/common';
|
3 | 3 |
|
4 | 4 | import {Animation} from '../../animations/animation';
|
@@ -188,19 +188,18 @@ export class ActionSheet extends ViewController {
|
188 | 188 | })
|
189 | 189 | class ActionSheetCmp {
|
190 | 190 | private d: any;
|
191 |
| - private keyUp: EventListener; |
192 | 191 |
|
193 | 192 | constructor(
|
194 | 193 | private _viewCtrl: ViewController,
|
195 | 194 | private _config: Config,
|
196 |
| - elementRef: ElementRef, |
| 195 | + private _elementRef: ElementRef, |
197 | 196 | params: NavParams,
|
198 | 197 | renderer: Renderer
|
199 | 198 | ) {
|
200 | 199 | this.d = params.data;
|
201 | 200 |
|
202 | 201 | if (this.d.cssClass) {
|
203 |
| - renderer.setElementClass(elementRef.nativeElement, this.d.cssClass, true); |
| 202 | + renderer.setElementClass(_elementRef.nativeElement, this.d.cssClass, true); |
204 | 203 | }
|
205 | 204 | }
|
206 | 205 |
|
@@ -234,16 +233,28 @@ class ActionSheetCmp {
|
234 | 233 | });
|
235 | 234 |
|
236 | 235 | this.d.buttons = buttons;
|
| 236 | + } |
| 237 | + |
| 238 | + onPageDidEnter() { |
| 239 | + let activeElement: any = document.activeElement; |
| 240 | + if (document.activeElement) { |
| 241 | + activeElement.blur(); |
| 242 | + } |
| 243 | + |
| 244 | + let focusableEle = this._elementRef.nativeElement.querySelector('button'); |
| 245 | + if (focusableEle) { |
| 246 | + focusableEle.focus(); |
| 247 | + } |
| 248 | + } |
237 | 249 |
|
238 |
| - let self = this; |
239 |
| - self.keyUp = function(ev: KeyboardEvent) { |
| 250 | + @HostListener('body:keyup', ['$event']) |
| 251 | + private _keyUp(ev: KeyboardEvent) { |
| 252 | + if (this._viewCtrl.isLast()) { |
240 | 253 | if (ev.keyCode === 27) {
|
241 | 254 | console.debug('actionsheet escape');
|
242 |
| - self.bdClick(); |
| 255 | + this.bdClick(); |
243 | 256 | }
|
244 |
| - }; |
245 |
| - |
246 |
| - document.addEventListener('keyup', this.keyUp); |
| 257 | + } |
247 | 258 | }
|
248 | 259 |
|
249 | 260 | click(button, dismissDelay?) {
|
@@ -278,14 +289,6 @@ class ActionSheetCmp {
|
278 | 289 | dismiss(role): Promise<any> {
|
279 | 290 | return this._viewCtrl.dismiss(null, role);
|
280 | 291 | }
|
281 |
| - |
282 |
| - onPageWillLeave() { |
283 |
| - document.removeEventListener('keyup', this.keyUp); |
284 |
| - } |
285 |
| - |
286 |
| - ngOnDestroy() { |
287 |
| - document.removeEventListener('keyup', this.keyUp); |
288 |
| - } |
289 | 292 | }
|
290 | 293 |
|
291 | 294 | export interface ActionSheetOptions {
|
|
0 commit comments