Skip to content

Commit cdf2c22

Browse files
authored
fix(codegen): only close dialog via buttons or on clicks outside (#38022)
1 parent 388bc6a commit cdf2c22

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

packages/injected/src/recorder/recorder.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,6 +1785,9 @@ class Dialog {
17851785
options.onCancel?.();
17861786
};
17871787

1788+
// Ensure any clicks in the dialog are caught, rather than passing through to the page and thus closing the dialog
1789+
this._dialogElement.addEventListener('click', event => event.stopPropagation());
1790+
17881791
const toolbarElement = this._recorder.document.createElement('x-pw-tools-list');
17891792
const labelElement = this._recorder.document.createElement('label');
17901793
labelElement.textContent = options.label;

tests/library/inspector/cli-codegen-3.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,36 @@ await page.GetByTestId("testid").HoverAsync();`);
895895
await expect(glassPane.locator('> x-pw-dialog .accept > x-div').evaluate(elem => getComputedStyle(elem).clipPath)).resolves.toBe('url("#icon-check")');
896896
await expect(glassPane.locator('> svg > defs > clipPath#icon-check')).toBeAttached();
897897
});
898+
899+
test('should keep dialog open when clicking inside', async ({ openRecorder }) => {
900+
const { page } = await openRecorder();
901+
await page.setContent('<div>hello</div>');
902+
903+
const assertTextButton = page.getByTitle('Assert text');
904+
const helloContent = page.getByText('hello');
905+
906+
await assertTextButton.click();
907+
await helloContent.click();
908+
909+
const dialog = page.locator('x-pw-dialog');
910+
await expect(dialog).toBeVisible();
911+
912+
await page.locator('x-pw-dialog x-pw-tools-list').click();
913+
await expect(dialog).toBeVisible();
914+
915+
await page.locator('x-pw-dialog textarea').click();
916+
await expect(dialog).toBeVisible();
917+
918+
await page.locator('x-pw-dialog .accept').click();
919+
await expect(dialog).toBeHidden();
920+
921+
await assertTextButton.click();
922+
await helloContent.click();
923+
await expect(dialog).toBeVisible();
924+
// Like the user clicking outside the dialog
925+
await page.locator('x-pw-glass').click();
926+
await expect(dialog).toBeHidden();
927+
});
898928
});
899929

900930
async function createFrameHierarchy(page: Page, recorder: Recorder, server: TestServer) {

0 commit comments

Comments
 (0)