Skip to content

Commit

Permalink
fix(modal, popover): remove trigger click listeners when overlay is u…
Browse files Browse the repository at this point in the history
…nmounted (#26167)
  • Loading branch information
amandaejohnston committed Oct 26, 2022
1 parent a7e15ba commit 1320948
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 8 deletions.
13 changes: 11 additions & 2 deletions core/src/components/modal/modal.tsx
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
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
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
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

0 comments on commit 1320948

Please sign in to comment.