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

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

Issue 2356643003: Fix cr-shared-menu focus issues. (Closed)
Patch Set: Created 4 years, 3 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 | « chrome/test/data/webui/cr_elements/cr_shared_menu_tests.js ('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 /** Same as paper-menu-button's custom easing cubic-bezier param. */ 5 /** Same as paper-menu-button's custom easing cubic-bezier param. */
6 var SLIDE_CUBIC_BEZIER = 'cubic-bezier(0.3, 0.95, 0.5, 1)'; 6 var SLIDE_CUBIC_BEZIER = 'cubic-bezier(0.3, 0.95, 0.5, 1)';
7 7
8 Polymer({ 8 Polymer({
9 is: 'cr-shared-menu', 9 is: 'cr-shared-menu',
10 10
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 return; 127 return;
128 128
129 if (this.menuOpen) 129 if (this.menuOpen)
130 this.closeMenu(); 130 this.closeMenu();
131 131
132 this.itemData = itemData; 132 this.itemData = itemData;
133 this.lastAnchor_ = anchor; 133 this.lastAnchor_ = anchor;
134 this.$.dropdown.restoreFocusOnClose = true; 134 this.$.dropdown.restoreFocusOnClose = true;
135 135
136 var focusableChildren = Polymer.dom(this).querySelectorAll( 136 var focusableChildren = Polymer.dom(this).querySelectorAll(
137 '[tabindex]:not([hidden]),button:not([hidden])'); 137 '[tabindex]:not([disabled]):not([hidden]),' +
138 'button:not([disabled]):not([hidden])');
138 if (focusableChildren.length > 0) { 139 if (focusableChildren.length > 0) {
139 this.$.dropdown.focusTarget = focusableChildren[0]; 140 this.$.dropdown.focusTarget = focusableChildren[0];
140 this.firstFocus_ = focusableChildren[0]; 141 this.firstFocus_ = focusableChildren[0];
141 this.lastFocus_ = focusableChildren[focusableChildren.length - 1]; 142 this.lastFocus_ = focusableChildren[focusableChildren.length - 1];
142 } 143 }
143 144
144 // Move the menu to the anchor. 145 // Move the menu to the anchor.
145 this.$.dropdown.positionTarget = anchor; 146 this.$.dropdown.positionTarget = anchor;
146 this.menuOpen = true; 147 this.menuOpen = true;
147 }, 148 },
(...skipping 18 matching lines...) Expand all
166 * @param {CustomEvent} e 167 * @param {CustomEvent} e
167 */ 168 */
168 onTabPressed_: function(e) { 169 onTabPressed_: function(e) {
169 if (!this.firstFocus_ || !this.lastFocus_) 170 if (!this.firstFocus_ || !this.lastFocus_)
170 return; 171 return;
171 172
172 var toFocus; 173 var toFocus;
173 var keyEvent = e.detail.keyboardEvent; 174 var keyEvent = e.detail.keyboardEvent;
174 if (keyEvent.shiftKey && keyEvent.target == this.firstFocus_) 175 if (keyEvent.shiftKey && keyEvent.target == this.firstFocus_)
175 toFocus = this.lastFocus_; 176 toFocus = this.lastFocus_;
176 else if (keyEvent.target == this.lastFocus_) 177 else if (!keyEvent.shiftKey && keyEvent.target == this.lastFocus_)
177 toFocus = this.firstFocus_; 178 toFocus = this.firstFocus_;
178 179
179 if (!toFocus) 180 if (!toFocus)
180 return; 181 return;
181 182
182 e.preventDefault(); 183 e.preventDefault();
183 toFocus.focus(); 184 toFocus.focus();
184 }, 185 },
185 186
186 /** 187 /**
(...skipping 12 matching lines...) Expand all
199 * Prevent focus restoring when tapping outside the menu. This stops the 200 * Prevent focus restoring when tapping outside the menu. This stops the
200 * focus moving around unexpectedly when closing the menu with the mouse. 201 * focus moving around unexpectedly when closing the menu with the mouse.
201 * @param {CustomEvent} e 202 * @param {CustomEvent} e
202 * @private 203 * @private
203 */ 204 */
204 onOverlayCanceled_: function(e) { 205 onOverlayCanceled_: function(e) {
205 if (e.detail.type == 'tap') 206 if (e.detail.type == 'tap')
206 this.$.dropdown.restoreFocusOnClose = false; 207 this.$.dropdown.restoreFocusOnClose = false;
207 }, 208 },
208 }); 209 });
OLDNEW
« no previous file with comments | « chrome/test/data/webui/cr_elements/cr_shared_menu_tests.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698