Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(modal, popover): remove trigger click listeners when overlay is unmounted #26167

Merged
merged 2 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions core/src/components/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,17 @@ export class Modal implements ComponentInterface, OverlayInterface {
}

connectedCallback() {
prepareOverlay(this.el);
const { configureTriggerInteraction, el } = this;
prepareOverlay(el);
configureTriggerInteraction();
}

disconnectedCallback() {
const { destroyTriggerInteraction } = this;

if (destroyTriggerInteraction) {
destroyTriggerInteraction();
}
}

componentWillLoad() {
Expand Down Expand Up @@ -371,7 +381,6 @@ export class Modal implements ComponentInterface, OverlayInterface {
raf(() => this.present());
}
this.breakpointsChanged(this.breakpoints);
this.configureTriggerInteraction();
}

private configureTriggerInteraction = () => {
Expand Down
23 changes: 21 additions & 2 deletions core/src/components/modal/test/trigger/modal.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,34 @@ import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';

test.describe('modal: trigger', () => {
test('should open modal by left clicking on trigger', async ({ page }) => {
test.beforeEach(async ({ page, skip }) => {
skip.rtl();
skip.mode('ios');
await page.goto('/src/components/modal/test/trigger');
});

test('should open modal by left clicking on trigger', async ({ page }) => {
const ionModalDidPresent = await page.spyOnEvent('ionModalDidPresent');

await page.click('#left-click-trigger');

await ionModalDidPresent.next();

const modal = await page.locator('.left-click-modal');
const modal = page.locator('.left-click-modal');
await expect(modal).toBeVisible();
});

test('should still open modal when it has been removed and re-added to DOM', async ({ page }) => {
const button = page.locator('#left-click-trigger');
const modal = page.locator('ion-modal');

await modal.evaluate((modal: HTMLIonModalElement) => {
modal.remove();
document.querySelector('ion-button')?.insertAdjacentElement('afterend', modal);
});
await page.waitForChanges();

await button.click();
await expect(modal).toBeVisible();
});
});
15 changes: 12 additions & 3 deletions core/src/components/popover/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,18 @@ export class Popover implements ComponentInterface, PopoverInterface {
@Event({ eventName: 'didDismiss' }) didDismissShorthand!: EventEmitter<OverlayEventDetail>;

connectedCallback() {
prepareOverlay(this.el);
const { configureTriggerInteraction, el } = this;

prepareOverlay(el);
configureTriggerInteraction();
}

disconnectedCallback() {
const { destroyTriggerInteraction } = this;

if (destroyTriggerInteraction) {
destroyTriggerInteraction();
}
}

componentWillLoad() {
Expand Down Expand Up @@ -344,8 +355,6 @@ export class Popover implements ComponentInterface, PopoverInterface {
this.dismiss(undefined, undefined, false);
});
}

this.configureTriggerInteraction();
}

/**
Expand Down
18 changes: 17 additions & 1 deletion core/src/components/popover/test/trigger/popover.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { test } from '@utils/test/playwright';
import { openPopover } from '../test.utils';

test.describe('popover: trigger', async () => {
test.beforeEach(async ({ page }) => {
test.beforeEach(async ({ page, skip }) => {
skip.rtl();
skip.mode('ios');
await page.goto('/src/components/popover/test/trigger');
});

Expand All @@ -32,6 +34,20 @@ test.describe('popover: trigger', async () => {

await checkPopover(page, '.hover-popover');
});

test('should still open popover when it has been removed and re-added to DOM', async ({ page }) => {
const button = page.locator('#left-click-trigger');
const popover = page.locator('.left-click-popover');

await popover.evaluate((popover: HTMLIonPopoverElement) => {
popover.remove();
document.querySelector('ion-button')?.insertAdjacentElement('afterend', popover);
});
await page.waitForChanges();

await button.click();
await expect(popover).toBeVisible();
});
});

const checkPopover = async (page: E2EPage, popoverSelector: string) => {
Expand Down