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

Side by Side Diff: ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js

Issue 2891993002: WebUI: Stop keypresses on the close icon from firing the Enter handler. (Closed)
Patch Set: Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « ui/webui/resources/cr_elements/cr_dialog/cr_dialog.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 'cr-dialog' is a component for showing a modal dialog. If the 6 * @fileoverview 'cr-dialog' is a component for showing a modal dialog. If the
7 * dialog is closed via close(), a 'close' event is fired. If the dialog is 7 * dialog is closed via close(), a 'close' event is fired. If the dialog is
8 * canceled via cancel(), a 'cancel' event is fired followed by a 'close' event. 8 * canceled via cancel(), a 'cancel' event is fired followed by a 'close' event.
9 * Additionally clients can inspect the dialog's |returnValue| property inside 9 * Additionally clients can inspect the dialog's |returnValue| property inside
10 * the 'close' event listener to determine whether it was canceled or just 10 * the 'close' event listener to determine whether it was canceled or just
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 }, 140 },
141 141
142 /** 142 /**
143 * @param {string=} opt_returnValue 143 * @param {string=} opt_returnValue
144 * @override 144 * @override
145 */ 145 */
146 close: function(opt_returnValue) { 146 close: function(opt_returnValue) {
147 HTMLDialogElement.prototype.close.call(this, 'success'); 147 HTMLDialogElement.prototype.close.call(this, 'success');
148 }, 148 },
149 149
150 /**
151 * @private
152 * @param {Event} e
153 */
154 onCloseKeypress_: function(e) {
155 // Because the dialog may have a default Enter key handler, prevent
156 // keypress events from bubbling up from this element.
157 e.stopPropagation();
158 },
159
150 /** @return {!PaperIconButtonElement} */ 160 /** @return {!PaperIconButtonElement} */
151 getCloseButton: function() { 161 getCloseButton: function() {
152 return this.$.close; 162 return this.$.close;
153 }, 163 },
154 164
155 /** 165 /**
156 * @param {!Event} e 166 * @param {!Event} e
157 * @private 167 * @private
158 */ 168 */
159 onKeypress_: function(e) { 169 onKeypress_: function(e) {
160 if (e.key != 'Enter') 170 if (e.key != 'Enter')
161 return; 171 return;
162 172
163 // Accept Enter keys from either the dialog, or a child paper-input element. 173 // Accept Enter keys from either the dialog, or a child paper-input element.
164 if (e.target != this && e.target.tagName != 'PAPER-INPUT') 174 if (e.target != this && e.target.tagName != 'PAPER-INPUT')
165 return; 175 return;
166 176
167 var actionButton = 177 var actionButton =
168 this.querySelector('.action-button:not([disabled]):not([hidden])'); 178 this.querySelector('.action-button:not([disabled]):not([hidden])');
169 if (actionButton) { 179 if (actionButton) {
170 actionButton.click(); 180 actionButton.click();
171 e.preventDefault(); 181 e.preventDefault();
172 } 182 }
173 }, 183 },
174 }); 184 });
OLDNEW
« no previous file with comments | « ui/webui/resources/cr_elements/cr_dialog/cr_dialog.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698