Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(730)

Unified Diff: ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js

Issue 2788673003: WebUI: For cr-dialog, make Enter click the action-button, if it exists. (Closed)
Patch Set: change closure annotations Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/data/webui/cr_elements/cr_dialog_test.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
+ }
+ },
});
« no previous file with comments | « chrome/test/data/webui/cr_elements/cr_dialog_test.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698