diff --git a/examples/playwright/src/tests/theia-main-menu.test.ts b/examples/playwright/src/tests/theia-main-menu.test.ts index 919cc0400b05f..6a250d274ff40 100644 --- a/examples/playwright/src/tests/theia-main-menu.test.ts +++ b/examples/playwright/src/tests/theia-main-menu.test.ts @@ -110,18 +110,17 @@ test.describe('Theia Main Menu', () => { expect(await fileDialog.isVisible()).toBe(false); }); - test('Create file via New File menu and cancel', async () => { - const openFileEntry = 'New File...'; - await (await menuBar.openMenu('File')).clickMenuItem(openFileEntry); + test('Create file via New File menu and accept', async () => { + await (await menuBar.openMenu('File')).clickMenuItem('New File...'); const quickPick = app.page.getByPlaceholder('Select File Type or Enter'); // type file name and press enter await quickPick.fill('test.txt'); await quickPick.press('Enter'); - // check file dialog is opened and accept with "Create File" button + // check file dialog is opened and accept with ENTER const fileDialog = await app.page.waitForSelector('div[class="dialogBlock"]'); expect(await fileDialog.isVisible()).toBe(true); - await app.page.locator('#theia-dialog-shell').getByRole('button', { name: 'Create File' }).click(); + await app.page.locator('#theia-dialog-shell').press('Enter'); expect(await fileDialog.isVisible()).toBe(false); // check file in workspace exists diff --git a/packages/filesystem/src/browser/file-dialog/file-dialog-widget.ts b/packages/filesystem/src/browser/file-dialog/file-dialog-widget.ts index fb52307421fe8..3ae225e521124 100644 --- a/packages/filesystem/src/browser/file-dialog/file-dialog-widget.ts +++ b/packages/filesystem/src/browser/file-dialog/file-dialog-widget.ts @@ -55,6 +55,17 @@ export class FileDialogWidget extends FileTreeWidget { return attr; } + protected override handleEnter(event: KeyboardEvent): boolean | void { + // Handle ENTER in the dialog to Accept. + // Tree view will just expand/collapse the node. This works also with arrow keys or SPACE. + return false; + } + + protected override handleEscape(event: KeyboardEvent): boolean | void { + // Handle ESC in the dialog to Cancel and close the Dialog. + return false; + } + protected override createNodeClassNames(node: TreeNode, props: NodeProps): string[] { const classNames = super.createNodeClassNames(node, props); if (this.shouldDisableSelection(node)) {