Index: ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js |
diff --git a/ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js b/ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js |
index d15ed9b8173a769d12afe886806d1509a99cfffc..9a1332ff14038c4fd380741a46b9762dfcab95ee 100644 |
--- a/ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js |
+++ b/ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js |
@@ -29,6 +29,14 @@ Polymer({ |
type: Boolean, |
value: false, |
}, |
+ |
+ /** |
+ * True if the dialog should ignore 'Enter' keypresses. |
+ */ |
+ ignoreEnterKey: { |
+ type: Boolean, |
+ value: false, |
+ }, |
}, |
/** @override */ |
@@ -39,6 +47,9 @@ Polymer({ |
if (!this.ignorePopstate && this.open) |
this.cancel(); |
}.bind(this)); |
+ |
+ if (!this.ignoreEnterKey) |
+ this.addEventListener('keypress', this.onKeypress_.bind(this)); |
}, |
cancel: function() { |
@@ -58,4 +69,21 @@ Polymer({ |
getCloseButton: function() { |
return this.$.close; |
}, |
+ |
+ /** |
+ * @param {!KeyboardEvent} e |
+ * @private |
+ */ |
+ onKeypress_: function(e) { |
+ if (e.target != this) |
tommycli
2017/03/31 00:16:55
This is more conservative than the Options equival
|
+ return; |
+ if (e.key != 'Enter') |
+ return; |
+ |
+ var actionButton = this.querySelector('.action-button'); |
dpapad
2017/03/31 02:08:29
Should we add an assertion() for this, instead of
tommycli
2017/04/03 16:53:34
Hey demetrios, here's an example where there's no
|
+ if (actionButton && !actionButton.disabled) { |
dpapad
2017/03/31 02:08:29
Do we need to check for |disabled| at all? I belie
tommycli
2017/04/03 16:53:34
Hi, disabled buttons can still be 'click()' ed. Se
dpapad
2017/04/03 18:20:07
Ok. I recall having problems "clicking" disabled b
|
+ actionButton.click(); |
+ e.preventDefault(); |
+ } |
+ }, |
}); |