Commit c3e29057 authored by Bailey Berro's avatar Bailey Berro Committed by Commit Bot

Fix focus change from OS Settings sidebar navigation

Previously, when navigating from the left hand nav in the narrow window
size, focus did not move properly to the correct section since the
drawer closing causes focus to move to the full settings page. By
delaying the route change until the drawer closes in the narrow case.

Fixed: 1026019
Change-Id: I280c9b91660221a7363baf2e0a914002bdb31fbb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1929980
Commit-Queue: Bailey Berro <baileyberro@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721276}
parent d65f8995
...@@ -84,12 +84,6 @@ Polymer({ ...@@ -84,12 +84,6 @@ Polymer({
*/ */
onSelectorActivate_: function(event) { onSelectorActivate_: function(event) {
this.setSelectedUrl_(event.detail.selected); this.setSelectedUrl_(event.detail.selected);
const path = new URL(event.detail.selected).pathname;
const route = settings.getRouteForPath(path);
assert(route, 'os-settings-menu has an entry with an invalid route.');
settings.navigateTo(
route, /* dynamicParams */ null, /* removeSearch */ true);
}, },
/** /**
......
...@@ -102,6 +102,13 @@ Polymer({ ...@@ -102,6 +102,13 @@ Polymer({
'refresh-pref': 'onRefreshPref_', 'refresh-pref': 'onRefreshPref_',
}, },
/**
* The route of the selected element in os-settings-menu. Stored here to defer
* navigation until drawer animation completes.
* @private {settings.Route}
*/
activeRoute_: null,
/** @override */ /** @override */
created: function() { created: function() {
settings.initializeRouteFromUrl(); settings.initializeRouteFromUrl();
...@@ -277,10 +284,23 @@ Polymer({ ...@@ -277,10 +284,23 @@ Polymer({
/** /**
* Called when a section is selected. * Called when a section is selected.
* @param {!Event} e
* @private * @private
*/ */
onIronActivate_: function() { onIronActivate_: function(e) {
this.$.drawer.close(); const section = e.detail.selected;
const path = new URL(section).pathname;
const route = settings.getRouteForPath(path);
assert(route, 'os-settings-menu has an entry with an invalid route.');
this.activeRoute_ = route;
if (this.isNarrow) {
// If the onIronActivate event came from the drawer, close the drawer and
// wait for the menu to close before navigating to |activeRoute_|.
this.$.drawer.close();
return;
}
this.navigateToActiveRoute_();
}, },
/** @private */ /** @private */
...@@ -288,6 +308,20 @@ Polymer({ ...@@ -288,6 +308,20 @@ Polymer({
this.$.drawer.toggle(); this.$.drawer.toggle();
}, },
/**
* Navigates to |activeRoute_| if set. Used to delay navigation until after
* animations complete to ensure focus ends up in the right place.
* @private
*/
navigateToActiveRoute_: function() {
if (this.activeRoute_) {
settings.navigateTo(
this.activeRoute_, /* dynamicParams */ null, /* removeSearch */ true);
this.activeRoute_ = null;
}
},
/** /**
* When this is called, The drawer animation is finished, and the dialog no * When this is called, The drawer animation is finished, and the dialog no
* longer has focus. The selected section will gain focus if one was selected. * longer has focus. The selected section will gain focus if one was selected.
...@@ -299,7 +333,8 @@ Polymer({ ...@@ -299,7 +333,8 @@ Polymer({
onMenuClose_: function() { onMenuClose_: function() {
if (!this.$.drawer.wasCanceled()) { if (!this.$.drawer.wasCanceled()) {
// If a navigation happened, MainPageBehavior#currentRouteChanged handles // If a navigation happened, MainPageBehavior#currentRouteChanged handles
// focusing the corresponding section. // focusing the corresponding section when we call settings.NavigateTo().
this.navigateToActiveRoute_();
return; return;
} }
......
...@@ -59,22 +59,6 @@ suite('OSSettingsMenu', function() { ...@@ -59,22 +59,6 @@ suite('OSSettingsMenu', function() {
Polymer.dom.flush(); Polymer.dom.flush();
assertNotEquals(openIcon, ironIconElement.icon); assertNotEquals(openIcon, ironIconElement.icon);
}); });
// Test that navigating via the paper menu always clears the current
// search URL parameter.
test('clearsUrlSearchParam', function() {
// As of iron-selector 2.x, need to force iron-selector to update before
// clicking items on it, or wait for 'iron-items-changed'
const ironSelector = settingsMenu.$$('iron-selector');
ironSelector.forceSynchronousItemUpdate();
const urlParams = new URLSearchParams('search=foo');
settings.navigateTo(settings.routes.BASIC, urlParams);
assertEquals(
urlParams.toString(), settings.getQueryParameters().toString());
settingsMenu.$.people.click();
assertEquals('', settings.getQueryParameters().toString());
});
}); });
suite('OSSettingsMenuReset', function() { suite('OSSettingsMenuReset', function() {
......
...@@ -216,6 +216,24 @@ TEST_F('OSSettingsUIBrowserTest', 'AllJsTests', () => { ...@@ -216,6 +216,24 @@ TEST_F('OSSettingsUIBrowserTest', 'AllJsTests', () => {
urlParams = settings.getQueryParameters(); urlParams = settings.getQueryParameters();
assertFalse(urlParams.has('search')); assertFalse(urlParams.has('search'));
}); });
// Test that navigating via the paper menu always clears the current
// search URL parameter.
test('clearsUrlSearchParam', function() {
const settingsMenu = ui.$$('os-settings-menu');
// As of iron-selector 2.x, need to force iron-selector to update before
// clicking items on it, or wait for 'iron-items-changed'
const ironSelector = settingsMenu.$$('iron-selector');
ironSelector.forceSynchronousItemUpdate();
const urlParams = new URLSearchParams('search=foo');
settings.navigateTo(settings.routes.BASIC, urlParams);
assertEquals(
urlParams.toString(), settings.getQueryParameters().toString());
settingsMenu.$.people.click();
assertEquals('', settings.getQueryParameters().toString());
});
}); });
mocha.run(); mocha.run();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment