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

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

Issue 2884113002: 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 }, 135 },
136 136
137 /** 137 /**
138 * @param {string=} opt_returnValue 138 * @param {string=} opt_returnValue
139 * @override 139 * @override
140 */ 140 */
141 close: function(opt_returnValue) { 141 close: function(opt_returnValue) {
142 HTMLDialogElement.prototype.close.call(this, 'success'); 142 HTMLDialogElement.prototype.close.call(this, 'success');
143 }, 143 },
144 144
145 /**
146 * @private
147 * @param {Event} e
148 */
149 stopPropagation_: function(e) {
dpapad 2017/05/15 23:20:56 Nit: Since this handler is only attached to the 'x
tommycli 2017/05/15 23:27:00 Done.
150 // Because the dialog may have a default Enter key handler, prevent
151 // keypress events from bubbling up from this element.
152 e.stopPropagation();
153 },
154
145 /** @return {!PaperIconButtonElement} */ 155 /** @return {!PaperIconButtonElement} */
146 getCloseButton: function() { 156 getCloseButton: function() {
147 return this.$.close; 157 return this.$.close;
148 }, 158 },
149 159
150 /** 160 /**
151 * @param {!Event} e 161 * @param {!Event} e
152 * @private 162 * @private
153 */ 163 */
154 onKeypress_: function(e) { 164 onKeypress_: function(e) {
155 if (e.key != 'Enter') 165 if (e.key != 'Enter')
156 return; 166 return;
157 167
158 // Accept Enter keys from either the dialog, or a child paper-input element. 168 // Accept Enter keys from either the dialog, or a child paper-input element.
159 if (e.target != this && e.target.tagName != 'PAPER-INPUT') 169 if (e.target != this && e.target.tagName != 'PAPER-INPUT')
160 return; 170 return;
161 171
162 var actionButton = 172 var actionButton =
163 this.querySelector('.action-button:not([disabled]):not([hidden])'); 173 this.querySelector('.action-button:not([disabled]):not([hidden])');
164 if (actionButton) { 174 if (actionButton) {
165 actionButton.click(); 175 actionButton.click();
166 e.preventDefault(); 176 e.preventDefault();
167 } 177 }
168 }, 178 },
169 }); 179 });
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