@@ -327,6 +327,7 @@ class AlertCmp {
327
327
private msgId : string ;
328
328
private inputType : string ;
329
329
private created : number ;
330
+ private lastClick : number ;
330
331
331
332
constructor (
332
333
private _viewCtrl : ViewController ,
@@ -350,6 +351,7 @@ class AlertCmp {
350
351
this . msgId = 'alert-msg-' + this . id ;
351
352
this . activeId = '' ;
352
353
this . created = Date . now ( ) ;
354
+ this . lastClick = 0 ;
353
355
354
356
if ( this . d . message ) {
355
357
this . descId = this . msgId ;
@@ -418,9 +420,15 @@ class AlertCmp {
418
420
private _keyUp ( ev : KeyboardEvent ) {
419
421
if ( this . isEnabled ( ) && this . _viewCtrl . isLast ( ) ) {
420
422
if ( ev . keyCode === 13 ) {
421
- console . debug ( 'alert, enter button' ) ;
422
- let button = this . d . buttons [ this . d . buttons . length - 1 ] ;
423
- this . btnClick ( button ) ;
423
+ if ( this . lastClick + 1000 < Date . now ( ) ) {
424
+ // do not fire this click if there recently was already a click
425
+ // this can happen when the button has focus and used the enter
426
+ // key to click the button. However, both the click handler and
427
+ // this keyup event will fire, so only allow one of them to go.
428
+ console . debug ( 'alert, enter button' ) ;
429
+ let button = this . d . buttons [ this . d . buttons . length - 1 ] ;
430
+ this . btnClick ( button ) ;
431
+ }
424
432
425
433
} else if ( ev . keyCode === 27 ) {
426
434
console . debug ( 'alert, escape button' ) ;
@@ -446,6 +454,9 @@ class AlertCmp {
446
454
return ;
447
455
}
448
456
457
+ // keep the time of the most recent button click
458
+ this . lastClick = Date . now ( ) ;
459
+
449
460
let shouldDismiss = true ;
450
461
451
462
if ( button . handler ) {
0 commit comments