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

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

Issue 2779903003: MD Settings: Potential <dialog> close focus workaround, WIP
Patch Set: Created 3 years, 8 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 | « no previous file | 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 25 matching lines...) Expand all
36 // If the active history entry changes (i.e. user clicks back button), 36 // If the active history entry changes (i.e. user clicks back button),
37 // all open dialogs should be cancelled. 37 // all open dialogs should be cancelled.
38 window.addEventListener('popstate', function() { 38 window.addEventListener('popstate', function() {
39 if (!this.ignorePopstate && this.open) 39 if (!this.ignorePopstate && this.open)
40 this.cancel(); 40 this.cancel();
41 }.bind(this)); 41 }.bind(this));
42 }, 42 },
43 43
44 cancel: function() { 44 cancel: function() {
45 this.fire('cancel'); 45 this.fire('cancel');
46 HTMLDialogElement.prototype.close.call(this, ''); 46 this.close('');
47 }, 47 },
48 48
49 /** 49 /**
50 * @param {string=} opt_returnValue 50 * @param {string=} opt_returnValue
51 * @override 51 * @override
52 */ 52 */
53 close: function(opt_returnValue) { 53 close: function(opt_returnValue) {
54 HTMLDialogElement.prototype.close.call(this, 'success'); 54 var returnValue = opt_returnValue == '' ? opt_returnValue : 'success';
55 // Moving the focus to a child of |this| that resides outside the
56 // |this.shadowRoot| seems to cause the focus to not be lost.
57 this.querySelector('paper-button').focus();
58 HTMLDialogElement.prototype.close.call(this, returnValue);
55 }, 59 },
56 60
57 /** @return {!PaperIconButtonElement} */ 61 /** @return {!PaperIconButtonElement} */
58 getCloseButton: function() { 62 getCloseButton: function() {
59 return this.$.close; 63 return this.$.close;
60 }, 64 },
61 }); 65 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698