mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix(alert): prevent both click and enter keyup from firing
This commit is contained in:
@@ -327,6 +327,7 @@ class AlertCmp {
|
||||
private msgId: string;
|
||||
private inputType: string;
|
||||
private created: number;
|
||||
private lastClick: number;
|
||||
|
||||
constructor(
|
||||
private _viewCtrl: ViewController,
|
||||
@@ -350,6 +351,7 @@ class AlertCmp {
|
||||
this.msgId = 'alert-msg-' + this.id;
|
||||
this.activeId = '';
|
||||
this.created = Date.now();
|
||||
this.lastClick = 0;
|
||||
|
||||
if (this.d.message) {
|
||||
this.descId = this.msgId;
|
||||
@@ -418,9 +420,15 @@ class AlertCmp {
|
||||
private _keyUp(ev: KeyboardEvent) {
|
||||
if (this.isEnabled() && this._viewCtrl.isLast()) {
|
||||
if (ev.keyCode === 13) {
|
||||
console.debug('alert, enter button');
|
||||
let button = this.d.buttons[this.d.buttons.length - 1];
|
||||
this.btnClick(button);
|
||||
if (this.lastClick + 1000 < Date.now()) {
|
||||
// do not fire this click if there recently was already a click
|
||||
// this can happen when the button has focus and used the enter
|
||||
// key to click the button. However, both the click handler and
|
||||
// this keyup event will fire, so only allow one of them to go.
|
||||
console.debug('alert, enter button');
|
||||
let button = this.d.buttons[this.d.buttons.length - 1];
|
||||
this.btnClick(button);
|
||||
}
|
||||
|
||||
} else if (ev.keyCode === 27) {
|
||||
console.debug('alert, escape button');
|
||||
@@ -446,6 +454,9 @@ class AlertCmp {
|
||||
return;
|
||||
}
|
||||
|
||||
// keep the time of the most recent button click
|
||||
this.lastClick = Date.now();
|
||||
|
||||
let shouldDismiss = true;
|
||||
|
||||
if (button.handler) {
|
||||
|
||||
Reference in New Issue
Block a user