From 076a787f6cd7f0d50b94c1ee2a305ea9e665ebc2 Mon Sep 17 00:00:00 2001 From: web-padawan Date: Mon, 29 Apr 2024 11:30:14 +0300 Subject: [PATCH] fix: clear reference to element removed from split-layout --- .../src/vaadin-split-layout-mixin.js | 6 +++++- .../split-layout/test/split-layout.common.js | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/split-layout/src/vaadin-split-layout-mixin.js b/packages/split-layout/src/vaadin-split-layout-mixin.js index 7b6a608ec7..9d1761e89b 100644 --- a/packages/split-layout/src/vaadin-split-layout-mixin.js +++ b/packages/split-layout/src/vaadin-split-layout-mixin.js @@ -56,7 +56,11 @@ export const SplitLayoutMixin = (superClass) => _cleanupNodes(nodes) { nodes.forEach((node) => { if (!(node.parentElement instanceof this.constructor)) { - node.removeAttribute('slot'); + const slot = node.getAttribute('slot'); + if (slot) { + this[`_${slot}Child`] = null; + node.removeAttribute('slot'); + } } }); } diff --git a/packages/split-layout/test/split-layout.common.js b/packages/split-layout/test/split-layout.common.js index 4c58351048..9988558ec7 100644 --- a/packages/split-layout/test/split-layout.common.js +++ b/packages/split-layout/test/split-layout.common.js @@ -421,6 +421,22 @@ describe('removing nodes', () => { await nextFrame(); expect(first.hasAttribute('slot')).to.be.false; }); + + it('should not update splitter position on the removed node', async () => { + splitLayout.removeChild(second); + await nextFrame(); + track(splitLayout.$.splitter, -10, 0); + expect(second.style.flex).to.be.not.ok; + }); + + it('should not dispatch `splitter-dragend` event if node is removed', async () => { + const spy = sinon.spy(); + splitLayout.addEventListener('splitter-dragend', spy); + splitLayout.removeChild(second); + await nextFrame(); + track(splitLayout.$.splitter, -10, 0); + expect(spy.called).to.be.false; + }); }); describe('moving nodes between layouts', () => {