Skip to content

Commit

Permalink
New File dialog doesn't accept Enter for default (#13582) (#14146)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhuebner authored Oct 29, 2024
1 parent fa7597a commit 9329805
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
9 changes: 4 additions & 5 deletions examples/playwright/src/tests/theia-main-menu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions packages/filesystem/src/browser/file-dialog/file-dialog-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 9329805

Please sign in to comment.