Skip to content

Commit 1bf9bcd

Browse files
fix: force size calculation on chart reattach (#10323) (#10327)
Co-authored-by: Diego Cardoso <diego@vaadin.com>
1 parent 83fccff commit 1bf9bcd

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/charts/src/vaadin-chart-mixin.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,10 @@ export const ChartMixin = (superClass) =>
756756
// Detect if the chart had already been initialized. This might happen in
757757
// environments where the chart is lazily attached (e.g Grid).
758758
if (this.configuration) {
759-
this.__reflow();
759+
const { height } = this.$.chart.style;
760+
this.$.chart.style.height = '0';
761+
this.configuration.setSize(null, null, false);
762+
this.$.chart.style.height = height;
760763
return;
761764
}
762765

packages/charts/test/reattach.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,25 @@ describe('reattach', () => {
259259
expect(chart.configuration.inverted).to.be.undefined;
260260
});
261261

262+
it('should restore default height when moving from different container with defined height', async () => {
263+
chart.style.height = '100%';
264+
await oneEvent(chart, 'chart-load');
265+
266+
const initialHeight = getComputedStyle(chart).height;
267+
268+
inner.style.height = '700px';
269+
inner.appendChild(chart);
270+
await oneEvent(chart, 'chart-redraw');
271+
272+
expect(getComputedStyle(chart).height).to.be.equal(inner.style.height);
273+
274+
// Move back to first parent
275+
wrapper.appendChild(chart);
276+
await nextFrame();
277+
278+
expect(getComputedStyle(chart).height).to.be.equal(initialHeight);
279+
});
280+
262281
describe('series', () => {
263282
let series;
264283

0 commit comments

Comments
 (0)