From c097b214430b1805ae3a3d3dd71b4c6b1474a869 Mon Sep 17 00:00:00 2001 From: Cory LaViska Date: Wed, 4 Dec 2024 12:03:49 -0500 Subject: [PATCH] backport SL-2274 --- src/components/popup/popup.test.ts | 23 +++++++++++++++++++++++ src/components/popup/popup.ts | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/components/popup/popup.test.ts b/src/components/popup/popup.test.ts index 8980635e0..e8bc38d31 100644 --- a/src/components/popup/popup.test.ts +++ b/src/components/popup/popup.test.ts @@ -1,8 +1,11 @@ import { expect } from '@open-wc/testing'; import { fixtures } from '../../internal/test/fixture.js'; import { html } from 'lit'; +import type WaPopup from './popup.js'; describe('', () => { + let element: WaPopup; + for (const fixture of fixtures) { describe(`with "${fixture.type}" rendering`, () => { it('should render a component', async () => { @@ -10,6 +13,26 @@ describe('', () => { expect(el).to.exist; }); + + it('should properly handle positioning when active changes', async () => { + element = await fixture(html``); + + element.active = true; + await element.updateComplete; + + // SImulate a scroll event + const event = new Event('scroll'); + window.dispatchEvent(event); + + element.active = false; + await element.updateComplete; + + // The component should not throw an error when the window is scrolled + expect(() => { + element.active = true; + window.dispatchEvent(event); + }).not.to.throw(); + }); }); } }); diff --git a/src/components/popup/popup.ts b/src/components/popup/popup.ts index 08a482cfd..33b74693b 100644 --- a/src/components/popup/popup.ts +++ b/src/components/popup/popup.ts @@ -276,7 +276,7 @@ export default class WaPopup extends WebAwesomeElement { private start() { // We can't start the positioner without an anchor - if (!this.anchorEl) { + if (!this.anchorEl || !this.active) { return; }