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

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: 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/browser/resources/settings/reset_page/reset_profile_dialog.html ('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 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();
+ }
+ },
});
« no previous file with comments | « chrome/browser/resources/settings/reset_page/reset_profile_dialog.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698