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 a84993e7e1fd185f8552ef825dac109ac91dce87..d598988232d717b2ce4eae42d65783c6a61e4ceb 100644 |
--- a/ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js |
+++ b/ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js |
@@ -30,6 +30,14 @@ Polymer({ |
value: false, |
}, |
+ /** |
+ * True if the dialog should ignore 'Enter' keypresses. |
+ */ |
+ ignoreEnterKey: { |
+ type: Boolean, |
+ value: false, |
+ }, |
+ |
showScrollBorders: { |
type: Boolean, |
value: false, |
@@ -48,6 +56,9 @@ Polymer({ |
if (!this.ignorePopstate && this.open) |
this.cancel(); |
}.bind(this)); |
+ |
+ if (!this.ignoreEnterKey) |
+ this.addEventListener('keypress', this.onKeypress_.bind(this)); |
}, |
/** @override */ |
@@ -96,4 +107,21 @@ Polymer({ |
getCloseButton: function() { |
return this.$.close; |
}, |
+ |
+ /** |
+ * @param {!Event} e |
+ * @private |
+ */ |
+ onKeypress_: function(e) { |
+ if (e.target != this) |
+ return; |
+ if (e.key != 'Enter') |
+ return; |
+ |
+ var actionButton = this.querySelector('.action-button'); |
+ if (actionButton && !actionButton.disabled) { |
+ actionButton.click(); |
+ e.preventDefault(); |
+ } |
+ }, |
}); |