Skip to content

Commit 5fd9211

Browse files
jackfranklinDevtools-frontend LUCI CQ
authored and
Devtools-frontend LUCI CQ
committed
Toolbar: fix title not updating on combo box
This CL fixes an issue where the title attribute does not update properly as the user changes which value is selected. Fixed: 407954458 Change-Id: Ic11f65b47994b6090231a38c93cb7d1e52d3deba Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6430024 Auto-Submit: Jack Franklin <jacktfranklin@chromium.org> Reviewed-by: Andres Olivares <andoli@chromium.org> Commit-Queue: Andres Olivares <andoli@chromium.org>
1 parent c035f3f commit 5fd9211

File tree

4 files changed

+52
-6
lines changed

4 files changed

+52
-6
lines changed

front_end/ui/legacy/Toolbar.test.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import * as Common from '../../core/common/common.js';
56
import {dispatchClickEvent, doubleRaf, renderElementIntoDOM} from '../../testing/DOMHelpers.js';
6-
import {describeWithLocale} from '../../testing/EnvironmentHelpers.js';
7+
import {describeWithEnvironment, describeWithLocale} from '../../testing/EnvironmentHelpers.js';
78
import * as RenderCoordinator from '../components/render_coordinator/render_coordinator.js';
89

910
import * as UI from './legacy.js';
@@ -209,4 +210,22 @@ describeWithLocale('Toolbar', () => {
209210
assert.isFalse(contextHandler.called);
210211
});
211212
});
213+
214+
describeWithEnvironment('ToolbarSettingComboBox', () => {
215+
it('updates its title with the currently active setting', async () => {
216+
const setting = Common.Settings.Settings.instance().createSetting<string>('test-combo-box-setting', 'option-1');
217+
setting.set('option-1');
218+
const box = new UI.Toolbar.ToolbarSettingComboBox(
219+
[{value: 'option-1', label: 'Option 1'}, {value: 'option-2', label: 'Option 2'}], setting, 'title-value');
220+
assert.strictEqual(box.element.title, 'Option 1');
221+
const options = box.options();
222+
// Ensure it works with select()
223+
box.select(options[1]);
224+
assert.strictEqual(box.element.title, 'Option 2');
225+
226+
// Ensure it works with setSelectedIndex()
227+
box.setSelectedIndex(0);
228+
assert.strictEqual(box.element.title, 'Option 1');
229+
});
230+
});
212231
});

front_end/ui/legacy/Toolbar.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,9 +1243,9 @@ export class ToolbarSettingComboBox extends ToolbarComboBox {
12431243
super(null, accessibleName, undefined, setting.name);
12441244
this.optionsInternal = options;
12451245
this.setting = setting;
1246-
this.element.addEventListener('change', this.valueChanged.bind(this), false);
1246+
this.element.addEventListener('change', this.onSelectValueChange.bind(this), false);
12471247
this.setOptions(options);
1248-
setting.addChangeListener(this.settingChanged, this);
1248+
setting.addChangeListener(this.onDevToolsSettingChanged, this);
12491249
}
12501250

12511251
setOptions(options: Option[]): void {
@@ -1265,7 +1265,29 @@ export class ToolbarSettingComboBox extends ToolbarComboBox {
12651265
return this.optionsInternal[this.selectedIndex()].value;
12661266
}
12671267

1268-
private settingChanged(): void {
1268+
override select(option: Element): void {
1269+
const index = Array.prototype.indexOf.call(this.element, option);
1270+
this.setSelectedIndex(index);
1271+
}
1272+
1273+
override setSelectedIndex(index: number): void {
1274+
super.setSelectedIndex(index);
1275+
const option = this.optionsInternal.at(index);
1276+
if (option) {
1277+
this.setTitle(option.label);
1278+
}
1279+
}
1280+
1281+
/**
1282+
* Note: wondering why there are two event listeners and what the difference is?
1283+
* It is because this combo box <select> is backed by a Devtools setting and
1284+
* at any time there could be multiple instances of these elements that are
1285+
* backed by the same setting. So they have to listen to two things:
1286+
* 1. When the setting is changed via a different method.
1287+
* 2. When the value of the select is changed, triggering a change to the setting.
1288+
*/
1289+
1290+
private onDevToolsSettingChanged(): void {
12691291
if (this.muteSettingListener) {
12701292
return;
12711293
}
@@ -1279,7 +1301,10 @@ export class ToolbarSettingComboBox extends ToolbarComboBox {
12791301
}
12801302
}
12811303

1282-
private valueChanged(_event: Event): void {
1304+
/**
1305+
* Run when the user interacts with the <select> element.
1306+
*/
1307+
private onSelectValueChange(_event: Event): void {
12831308
const option = this.optionsInternal[this.selectedIndex()];
12841309
this.muteSettingListener = true;
12851310
this.setting.set(option.value);

front_end/ui/visual_logging/KnownContextValues.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3433,6 +3433,7 @@ export const knownContextValues = new Set([
34333433
'terms-of-service.console-insights',
34343434
'test',
34353435
'test-action',
3436+
'test-combo-box-setting',
34363437
'test-device',
34373438
'test-font',
34383439
'test-setting',

test/e2e/performance/timeline/treeView_test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ describe('The Performance tool, Bottom-up panel', function() {
153153
if (!rootActivity) {
154154
assert.fail(`Could not find ${expectedActivities[0]} in frontend.`);
155155
}
156-
const dropdown = await waitFor('select[aria-label="Group by"]');
156+
157+
const dropdown = await waitFor('select[aria-label="No grouping"]');
157158
await dropdown.evaluate(el => {
158159
(el as HTMLSelectElement).selectedIndex = 2;
159160
el.dispatchEvent(new Event('change'));

0 commit comments

Comments
 (0)