Skip to content

Commit cbde6b1

Browse files
Nancy LiDevtools-frontend LUCI CQ
authored andcommitted
Update shortcut dialog to use new ButtonDialog component
Bug: 379036632 Change-Id: I611a2b99febfa99043a4b42ef1141d6370ba8510 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6023184 Reviewed-by: Alina Varkki <[email protected]> Reviewed-by: Kateryna Prokopenko <[email protected]> Commit-Queue: Nancy Li <[email protected]>
1 parent 247400d commit cbde6b1

20 files changed

+31
-145
lines changed

front_end/ui/components/dialogs/ShortcutDialog.test.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,15 @@ describeWithLocale('ShortcutDialog', () => {
2727

2828
function getDialogFromShortcutDialog(shortcutDialog: Dialogs.ShortcutDialog.ShortcutDialog) {
2929
assert.isNotNull(shortcutDialog.shadowRoot);
30-
const dialog = shortcutDialog.shadowRoot.querySelector('devtools-dialog');
30+
const dialog = shortcutDialog.shadowRoot.querySelector('devtools-button-dialog');
3131
if (!dialog) {
32-
assert.fail('devtools-dialog not found');
32+
assert.fail('devtools-button-dialog not found');
3333
}
3434
assert.instanceOf(dialog, HTMLElement);
3535
return dialog;
3636
}
3737

38-
it('should display dialog on initial render when provided prop', async () => {
39-
const shortcutDialog = await getShortcutDialog(true);
40-
const dialog = getDialogFromShortcutDialog(shortcutDialog);
41-
42-
assert.isTrue(dialog.hasAttribute('open'));
43-
});
44-
45-
it('should not display dialog on initial render by default', async () => {
46-
const shortcutDialog = await getShortcutDialog();
47-
const dialog = getDialogFromShortcutDialog(shortcutDialog);
48-
49-
assert.isFalse(dialog.hasAttribute('open'));
50-
});
51-
52-
it('prepends provived element to the dialog content', async () => {
38+
it('prepends provided element to the dialog content', async () => {
5339
const prependedElement = document.createElement('div');
5440
prependedElement.classList.add('prepended-element');
5541

front_end/ui/components/dialogs/ShortcutDialog.ts

Lines changed: 11 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
// Copyright 2023 The Chromium Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4+
import './ButtonDialog.js';
45

56
import * as i18n from '../../../core/i18n/i18n.js';
67
import type * as Platform from '../../../core/platform/platform.js';
78
import * as Buttons from '../../../ui/components/buttons/buttons.js';
89
import * as ComponentHelpers from '../../../ui/components/helpers/helpers.js';
910
import * as LitHtml from '../../../ui/lit-html/lit-html.js';
10-
import * as VisualLogging from '../../../ui/visual_logging/visual_logging.js';
11-
12-
import {
13-
type ClickOutsideDialogEvent,
14-
type Dialog as DialogElement,
15-
DialogHorizontalAlignment,
16-
DialogVerticalPosition,
17-
} from './Dialog.js';
11+
12+
import type {ButtonDialogData} from './ButtonDialog.js';
1813
import shortcutDialogStyles from './shortcutDialog.css.js';
1914

2015
const {html} = LitHtml;
@@ -29,10 +24,6 @@ const UIStrings = {
2924
* @description Title of the keyboard shortcuts help menu.
3025
*/
3126
dialogTitle: 'Keyboard shortcuts',
32-
/**
33-
* @description Title of close button for the shortcuts dialog.
34-
*/
35-
close: 'Close',
3627
};
3728

3829
const str_ = i18n.i18n.registerUIStrings('ui/components/dialogs/ShortcutDialog.ts', UIStrings);
@@ -44,14 +35,6 @@ declare global {
4435
}
4536
}
4637

47-
export class ShowDialog extends Event {
48-
static readonly eventName = 'showdialog';
49-
50-
constructor() {
51-
super(ShowDialog.eventName);
52-
}
53-
}
54-
5538
export interface Shortcut {
5639
title: string|Platform.UIString.LocalizedString;
5740
bindings: string[];
@@ -65,8 +48,6 @@ export class ShortcutDialog extends HTMLElement {
6548
readonly #shadow = this.attachShadow({mode: 'open'});
6649
readonly #renderBound = this.#render.bind(this);
6750

68-
#dialog: DialogElement|null = null;
69-
#showButton: Buttons.Button.Button|null = null;
7051
#shortcuts: Shortcut[] = [];
7152
#openOnRender = false;
7253
#prependedElement: HTMLElement|null = null;
@@ -84,26 +65,6 @@ export class ShortcutDialog extends HTMLElement {
8465
void ComponentHelpers.ScheduledRender.scheduleRender(this, this.#renderBound);
8566
}
8667

87-
#showDialog(): void {
88-
if (!this.#dialog) {
89-
throw new Error('Dialog not found');
90-
}
91-
void this.#dialog.setDialogVisible(true);
92-
void ComponentHelpers.ScheduledRender.scheduleRender(this, this.#renderBound);
93-
this.dispatchEvent(new ShowDialog());
94-
}
95-
96-
#closeDialog(evt?: ClickOutsideDialogEvent): void {
97-
if (!this.#dialog) {
98-
throw new Error('Dialog not found');
99-
}
100-
void this.#dialog.setDialogVisible(false);
101-
if (evt) {
102-
evt.stopImmediatePropagation();
103-
}
104-
void ComponentHelpers.ScheduledRender.scheduleRender(this, this.#renderBound);
105-
}
106-
10768
#getKeysFromBinding(binding: string): string[] {
10869
return binding.split(/[\s+]+/).map(word => word.trim()); // Split on one or more spaces or + symbols
10970
}
@@ -120,47 +81,16 @@ export class ShortcutDialog extends HTMLElement {
12081
// clang-format off
12182
LitHtml.render(
12283
html`
123-
<devtools-button
124-
@click=${this.#showDialog}
125-
on-render=${ComponentHelpers.Directives.nodeRenderedCallback(node => {
126-
this.#showButton = node as Buttons.Button.Button;
127-
})}
128-
.data=${{
84+
<devtools-button-dialog .data=${{
85+
openOnRender: this.#openOnRender,
86+
closeButton: true,
87+
dialogTitle: i18nString(UIStrings.dialogTitle),
12988
variant: Buttons.Button.Variant.TOOLBAR,
13089
iconName: 'help',
131-
title: i18nString(UIStrings.showShortcutTitle),
132-
} as Buttons.Button.ButtonData}
133-
></devtools-button>
134-
<devtools-dialog
135-
class="shortcuts-dialog"
136-
@clickoutsidedialog=${this.#closeDialog}
137-
.origin=${() => {
138-
if (!this.#showButton) {
139-
throw new Error('Button not found');
140-
}
141-
return this.#showButton;
142-
}}
143-
.position=${DialogVerticalPosition.BOTTOM}
144-
.horizontalAlignment=${DialogHorizontalAlignment.RIGHT}
145-
.jslogContext=${'shortcuts'}
146-
on-render=${ComponentHelpers.Directives.nodeRenderedCallback(node => {
147-
this.#dialog = node as DialogElement;
148-
})}
149-
>
150-
<div class="keybinds-category-header">
151-
<span class="keybinds-category-header-text">${i18nString(UIStrings.dialogTitle)}</span>
152-
<devtools-button
153-
@click=${this.#closeDialog}
154-
.data=${{
155-
variant: Buttons.Button.Variant.TOOLBAR,
156-
iconName: 'cross',
157-
title: i18nString(UIStrings.close),
158-
} as Buttons.Button.ButtonData}
159-
jslog=${VisualLogging.close().track({click: true})}
160-
></devtools-button>
161-
</div>
162-
${(this.#prependedElement) ? html`${this.#prependedElement}` : LitHtml.nothing}
90+
iconTitle: i18nString(UIStrings.showShortcutTitle),
91+
} as ButtonDialogData}>
16392
<ul class="keybinds-list">
93+
${(this.#prependedElement) ? html`${this.#prependedElement}` : LitHtml.nothing}
16494
${this.#shortcuts.map(shortcut =>
16595
html`
16696
<li class="keybinds-list-item">
@@ -179,15 +109,10 @@ export class ShortcutDialog extends HTMLElement {
179109
</li>`,
180110
)}
181111
</ul>
182-
</devtools-dialog>
112+
</devtools-button-dialog>
183113
`,
184114
this.#shadow, {host: this});
185115
// clang-format on
186-
187-
if (this.#openOnRender) {
188-
this.#showDialog();
189-
this.#openOnRender = false;
190-
}
191116
}
192117
}
193118

front_end/ui/components/dialogs/shortcutDialog.css

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
* found in the LICENSE file.
55
*/
66

7-
.shortcuts-dialog {
8-
/* overwrite 'white-space: pre' in the toolbar item parent element */
9-
white-space: nowrap;
10-
}
11-
127
.keybinds-category-header {
138
display: flex;
149
justify-content: space-between;
@@ -24,8 +19,9 @@
2419
.keybinds-list {
2520
display: flex;
2621
flex-direction: column;
22+
/* overwrite default`margin` and `padding` for the <ul> element */
2723
margin: 0;
28-
padding: 0 var(--sys-size-8) var(--sys-size-3) var(--sys-size-8);
24+
padding: 0;
2925
}
3026

3127
.keybinds-list-item {

front_end/ui/components/docs/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ group("docs") {
5353
"./report",
5454
"./request_link_icon",
5555
"./select_menu",
56-
"./shortcut_dialog",
5756
"./style_property_editor",
5857
"./survey_link",
5958
"./switch",

front_end/ui/components/docs/dialog/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ ts_library("ts") {
1010
sources = [
1111
"basic.ts",
1212
"button_dialog.ts",
13+
"shortcut_dialog.ts",
1314
]
1415

1516
deps = [
@@ -24,6 +25,7 @@ copy_to_gen("dialog") {
2425
sources = [
2526
"basic.html",
2627
"button_dialog.html",
28+
"shortcut_dialog.html",
2729
]
2830
deps = [ ":ts" ]
2931
}

front_end/ui/components/docs/shortcut_dialog/basic.html renamed to front_end/ui/components/docs/dialog/shortcut_dialog.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323

2424
<body>
2525
<div id="container"></div>
26-
<script src="./basic.js" type="module"></script>
26+
<script src="./shortcut_dialog.js" type="module"></script>
2727
</body>
2828
</html>

front_end/ui/components/docs/shortcut_dialog/basic.ts renamed to front_end/ui/components/docs/dialog/shortcut_dialog.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +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 ComponentHelpers from '../../../../../front_end/ui/components/helpers/helpers.js';
65
import * as FrontendHelpers from '../../../../testing/EnvironmentHelpers.js'; // eslint-disable-line rulesdir/es_modules_import
7-
import * as Dialogs from '../../../../ui/components/dialogs/dialogs.js';
6+
import * as Dialogs from '../../dialogs/dialogs.js';
7+
import * as ComponentHelpers from '../../helpers/helpers.js';
88

99
await ComponentHelpers.ComponentServerSetup.setup();
1010
await FrontendHelpers.initializeGlobalVars();

front_end/ui/components/docs/shortcut_dialog/BUILD.gn

Lines changed: 0 additions & 23 deletions
This file was deleted.

test/e2e/recorder/ui_test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,14 @@ describe('Recorder', function() {
329329
const {frontend} = getBrowserAndPages();
330330
await frontend.bringToFront();
331331
const shortcutDialog = await waitFor('devtools-shortcut-dialog');
332+
const buttonDialog = await waitFor('devtools-button-dialog', shortcutDialog);
332333

333-
await click('devtools-button', {root: shortcutDialog});
334+
await click('devtools-button', {root: buttonDialog});
334335

335-
const dialog = await waitFor('devtools-dialog', shortcutDialog);
336+
const dialog = await waitFor('devtools-dialog', buttonDialog);
336337
assert.isOk(dialog);
337338

338-
const shortcuts = await $$('.keybinds-list-item', dialog);
339+
const shortcuts = await $$('.keybinds-list-item', buttonDialog);
339340
assert.lengthOf(shortcuts, 4);
340341
});
341342
});

test/interactions/goldens/linux/shortcut_dialog/shortcut_dialog_closed.png renamed to test/interactions/goldens/linux/dialog/shortcut_dialog_closed.png

File renamed without changes.

0 commit comments

Comments
 (0)