Skip to content

Commit 0a6af20

Browse files
ktranDevtools-frontend LUCI CQ
authored andcommitted
[GM3Restyling] Use details element to show details in Infobar
This adds a details element and removes the "Show more" link that was previously gating the details. Drive-by: Remove 'highlight' option. We can already set the button type, and focus problem after clicking "Show more" doesn't exist anymore since we use the details element. Screenshot: https://imgur.com/a/cG8CeFG Bug: 325443174 Change-Id: I3d906fc2ec4a48725554666a01e0498bdbdaf145 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6336213 Commit-Queue: Kim-Anh Tran <[email protected]> Reviewed-by: Kateryna Prokopenko <[email protected]>
1 parent 22de342 commit 0a6af20

File tree

8 files changed

+98
-122
lines changed

8 files changed

+98
-122
lines changed

front_end/panels/sources/DebuggerPlugin.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,15 +430,13 @@ export class DebuggerPlugin extends Plugin {
430430
[
431431
{
432432
text: i18nString(UIStrings.configure),
433-
highlight: false,
434433
delegate:
435434
UI.ViewManager.ViewManager.instance().showView.bind(UI.ViewManager.ViewManager.instance(), 'blackbox'),
436435
dismiss: false,
437436
jslogContext: 'configure',
438437
},
439438
{
440439
text: i18nString(UIStrings.removeFromIgnoreList),
441-
highlight: false,
442440
delegate: unIgnoreList,
443441
buttonVariant: Buttons.Button.Variant.TONAL,
444442
dismiss: true,

front_end/panels/sources/SourcesNavigator.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ export class FilesNavigatorView extends NavigatorView {
260260
i18nString(UIStrings.automaticWorkspaceFolderDetected, {PH1: automaticFileSystem.root}),
261261
[{
262262
text: i18nString(UIStrings.automaticWorkspaceFolderConnect),
263-
highlight: true,
264263
delegate: () => this.#automaticFileSystemManager.connectAutomaticFileSystem(/* addIfMissing= */ true),
265264
dismiss: true,
266265
jslogContext: 'automatic-workspace-folders.connect',

front_end/ui/legacy/Infobar.test.ts

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,39 @@
33
// found in the LICENSE file.
44

55
import {
6-
dispatchClickEvent,
76
renderElementIntoDOM,
87
} from '../../testing/DOMHelpers.js';
98
import {
10-
deinitializeGlobalVars,
11-
initializeGlobalVars,
9+
describeWithEnvironment,
1210
} from '../../testing/EnvironmentHelpers.js';
13-
import * as Buttons from '../components/buttons/buttons.js';
1411

1512
import * as UI from './legacy.js';
1613

17-
describe('Infobar', () => {
18-
before(async () => {
19-
await initializeGlobalVars();
20-
});
21-
22-
after(async () => {
23-
await deinitializeGlobalVars();
24-
});
25-
14+
describeWithEnvironment('Infobar', () => {
2615
const checkDetailsMessage = (component: UI.Infobar.Infobar, messageText: string) => {
2716
renderElementIntoDOM(component.element);
2817

2918
const infobar = component.element.shadowRoot!.querySelector('.infobar');
3019
assert.instanceOf(infobar, HTMLDivElement);
31-
const learnMoreButton = infobar.querySelector('devtools-button');
32-
assert.instanceOf(learnMoreButton, Buttons.Button.Button);
33-
const detailsRow = infobar.querySelector('.infobar-details-rows');
34-
assert.instanceOf(detailsRow, HTMLDivElement);
35-
36-
assert.isTrue(detailsRow.classList.contains('hidden'), 'Details row should initially be hidden');
37-
assert.strictEqual(detailsRow.textContent, messageText);
38-
39-
dispatchClickEvent(learnMoreButton);
40-
assert.isFalse(
41-
detailsRow.classList.contains('hidden'),
42-
'Details row should not be hidden after clicking on learn-more-button');
20+
const details = infobar.querySelector('details');
21+
assert.exists(details);
22+
assert.isFalse(details.hasAttribute('open'));
23+
24+
const detailsRow = details.querySelector('.infobar-details-rows');
25+
assert.strictEqual(detailsRow?.textContent, messageText);
26+
27+
const summary = details.querySelector('summary');
28+
assert.exists(summary);
29+
summary.click();
30+
assert.isTrue(details.hasAttribute('open'));
4331
};
4432

33+
it('shows main message', () => {
34+
const component = new UI.Infobar.Infobar(UI.Infobar.Type.WARNING, 'This is a warning');
35+
assert.deepEqual(
36+
component.element.shadowRoot?.querySelector('.infobar-main-row')?.textContent, 'This is a warning');
37+
});
38+
4539
it('shows details message containing a string', () => {
4640
const component = new UI.Infobar.Infobar(UI.Infobar.Type.WARNING, 'This is a warning');
4741
const messageText = 'This is a more detailed warning';

front_end/ui/legacy/Infobar.ts

Lines changed: 14 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ const UIStrings = {
1919
*@description Text on a button to close the infobar and never show the infobar in the future
2020
*/
2121
dontShowAgain: 'Don\'t show again',
22-
/**
23-
*@description Text that indicates that a short message can be expanded to a detailed message
24-
*/
25-
showMore: 'Show more',
2622
/**
2723
*@description Text to close something
2824
*/
@@ -35,21 +31,16 @@ export class Infobar {
3531
element: HTMLElement;
3632
private readonly shadowRoot: ShadowRoot;
3733
private readonly contentElement: HTMLDivElement;
38-
private readonly mainRow: HTMLElement;
39-
private readonly detailsRows: HTMLElement;
40-
private hasDetails: boolean;
41-
private detailsMessage: string|Element;
34+
private detailsRows?: HTMLElement;
4235
private readonly infoContainer: HTMLElement;
4336
private readonly infoMessage: HTMLElement;
4437
private infoText: HTMLElement;
4538
private readonly actionContainer: HTMLElement;
4639
private readonly disableSetting: Common.Settings.Setting<boolean>|null;
47-
private readonly closeContainer: HTMLElement;
48-
private readonly toggleElement: Buttons.Button.Button;
4940
private readonly closeButton: DevToolsCloseButton;
5041
private closeCallback: (() => void)|null;
51-
#firstFocusableElement: HTMLElement|null = null;
5242
private parentView?: Widget;
43+
mainRow: HTMLElement;
5344

5445
constructor(
5546
type: Type, text: string, actions?: InfobarAction[], disableSetting?: Common.Settings.Setting<boolean>,
@@ -63,19 +54,13 @@ export class Infobar {
6354
this.shadowRoot = createShadowRootWithCoreStyles(this.element, {cssFile: infobarStyles});
6455

6556
this.contentElement = this.shadowRoot.createChild('div', 'infobar infobar-' + type);
57+
const icon = IconButton.Icon.create(TYPE_TO_ICON[type], type + '-icon');
58+
this.contentElement.createChild('div', 'icon-container').appendChild(icon);
6659

6760
this.mainRow = this.contentElement.createChild('div', 'infobar-main-row');
68-
this.detailsRows = this.contentElement.createChild('div', 'infobar-details-rows hidden');
69-
this.hasDetails = false;
70-
this.detailsMessage = '';
71-
7261
this.infoContainer = this.mainRow.createChild('div', 'infobar-info-container');
73-
7462
this.infoMessage = this.infoContainer.createChild('div', 'infobar-info-message');
7563

76-
const icon = IconButton.Icon.create(TYPE_TO_ICON[type], type + '-icon');
77-
this.infoMessage.appendChild(icon);
78-
7964
this.infoText = this.infoMessage.createChild('div', 'infobar-info-text');
8065
this.infoText.textContent = text;
8166
ARIAUtils.markAsAlert(this.infoText);
@@ -104,20 +89,11 @@ export class Infobar {
10489
jslogContext: action.jslogContext,
10590
variant: buttonVariant,
10691
});
107-
if (action.highlight && !this.#firstFocusableElement) {
108-
this.#firstFocusableElement = button;
109-
}
11092
this.actionContainer.appendChild(button);
11193
}
11294
}
11395

114-
this.closeContainer = this.mainRow.createChild('div', 'infobar-close-container');
115-
this.toggleElement = createTextButton(
116-
i18nString(UIStrings.showMore), this.onToggleDetails.bind(this),
117-
{className: 'hidden show-more', jslogContext: 'show-more', variant: Buttons.Button.Variant.TEXT});
118-
this.toggleElement.setAttribute('role', 'link');
119-
this.closeContainer.appendChild(this.toggleElement);
120-
this.closeButton = this.closeContainer.createChild('dt-close-button', 'close-button');
96+
this.closeButton = this.contentElement.createChild('dt-close-button', 'icon-container');
12197
this.closeButton.setTabbable(true);
12298
this.closeButton.setSize(Buttons.Button.Size.SMALL);
12399
ARIAUtils.setDescription(this.closeButton, i18nString(UIStrings.close));
@@ -133,16 +109,6 @@ export class Infobar {
133109
event.consume();
134110
return;
135111
}
136-
137-
if (event.target !== this.contentElement) {
138-
return;
139-
}
140-
141-
if (event.key === 'Enter' && this.hasDetails) {
142-
this.onToggleDetails();
143-
event.consume();
144-
return;
145-
}
146112
});
147113

148114
this.closeCallback = null;
@@ -208,23 +174,16 @@ export class Infobar {
208174
this.dispose();
209175
}
210176

211-
private onToggleDetails(): void {
212-
this.detailsRows.classList.remove('hidden');
213-
this.toggleElement.remove();
214-
this.onResize();
215-
ARIAUtils.alert(
216-
typeof this.detailsMessage === 'string' ? this.detailsMessage : this.detailsMessage.textContent || '');
217-
if (this.#firstFocusableElement) {
218-
this.#firstFocusableElement.focus();
219-
} else {
220-
this.closeButton.focus();
221-
}
222-
}
223-
224177
createDetailsRowMessage(message: Element|string): Element {
225-
this.hasDetails = true;
226-
this.detailsMessage = message;
227-
this.toggleElement.classList.remove('hidden');
178+
if (!this.detailsRows) {
179+
const details = document.createElement('details');
180+
const summary = details.createChild('summary');
181+
const triangleIcon = IconButton.Icon.create('arrow-drop-down');
182+
summary.createChild('div', 'icon-container').appendChild(triangleIcon);
183+
this.contentElement.insertBefore(details, this.mainRow);
184+
summary.appendChild(this.mainRow);
185+
this.detailsRows = details.createChild('div', 'infobar-details-rows');
186+
}
228187
const infobarDetailsRow = this.detailsRows.createChild('div', 'infobar-details-row');
229188
const detailsRowMessage = infobarDetailsRow.createChild('span', 'infobar-row-message');
230189
if (typeof message === 'string') {
@@ -237,7 +196,6 @@ export class Infobar {
237196
}
238197
export interface InfobarAction {
239198
text: string;
240-
highlight: boolean;
241199
delegate: (() => void)|null;
242200
dismiss: boolean;
243201
buttonVariant?: Buttons.Button.Variant;

front_end/ui/legacy/InspectorView.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,6 @@ export class InspectorView extends VBox implements ViewLocationResolver {
485485
[
486486
{
487487
text: i18nString(UIStrings.reloadDebuggedTab),
488-
highlight: true,
489488
delegate: () => {
490489
reloadDebuggedTab();
491490
this.removeDebuggedTabReloadRequiredWarning();
@@ -518,7 +517,6 @@ export class InspectorView extends VBox implements ViewLocationResolver {
518517
[
519518
{
520519
text: i18nString(UIStrings.reloadDevtools),
521-
highlight: true,
522520
delegate: () => reloadDevTools(),
523521
dismiss: false,
524522
buttonVariant: Buttons.Button.Variant.PRIMARY,
@@ -542,7 +540,6 @@ export class InspectorView extends VBox implements ViewLocationResolver {
542540
[
543541
{
544542
text: i18nString(UIStrings.selectFolder),
545-
highlight: true,
546543
delegate: () => callback(),
547544
dismiss: true,
548545
buttonVariant: Buttons.Button.Variant.TONAL,
@@ -608,7 +605,6 @@ function createLocaleInfobar(): Infobar {
608605
[
609606
{
610607
text: i18nString(UIStrings.setToBrowserLanguage),
611-
highlight: true,
612608
delegate: () => {
613609
languageSetting.set('browserLanguage');
614610
getDisableLocaleInfoBarSetting().set(true);
@@ -619,7 +615,6 @@ function createLocaleInfobar(): Infobar {
619615
},
620616
{
621617
text: i18nString(UIStrings.setToSpecificLanguage, {PH1: closestSupportedLanguageInCurrentLocale}),
622-
highlight: true,
623618
delegate: () => {
624619
languageSetting.set(closestSupportedLocale);
625620
getDisableLocaleInfoBarSetting().set(true);

0 commit comments

Comments
 (0)