mirror of
https://github.com/shoelace-style/shoelace.git
synced 2026-01-12 02:59:13 +00:00
Fix/memory leak popup (#2274)
* fix(popup): start positioner only if active * test(popup): add test for positioning behavior on active state change * fix(popup): ensure positioner starts only when active and anchor is present
This commit is contained in:
committed by
GitHub
parent
9f401f8e8b
commit
a764672d03
@@ -272,8 +272,8 @@ export default class SlPopup extends ShoelaceElement {
|
||||
}
|
||||
|
||||
private start() {
|
||||
// We can't start the positioner without an anchor
|
||||
if (!this.anchorEl) {
|
||||
// We can't start the positioner without an anchor or when the popup is inactive
|
||||
if (!this.anchorEl || !this.active) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,33 @@
|
||||
import '../../../dist/shoelace.js';
|
||||
import { expect, fixture, html } from '@open-wc/testing';
|
||||
import type SlPopup from './popup.js';
|
||||
|
||||
describe('<sl-popup>', () => {
|
||||
let element: SlPopup;
|
||||
|
||||
it('should render a component', async () => {
|
||||
const el = await fixture(html` <sl-popup></sl-popup> `);
|
||||
|
||||
expect(el).to.exist;
|
||||
});
|
||||
|
||||
it('should properly handle positioning when active changes', async () => {
|
||||
element = await fixture('<sl-popup></sl-popup>');
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user