Skip to content

Commit 3399e37

Browse files
authored
fix: remove responsive step styles when switching to auto-responsive (#8860)
* fix: do not force layout update immediately * wip * update snapshots
1 parent 11031d7 commit 3399e37

3 files changed

Lines changed: 113 additions & 1 deletion

File tree

packages/form-layout/src/layouts/responsive-steps-layout.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ export class ResponsiveStepsLayout extends AbstractLayout {
5353
requestAnimationFrame(() => this.updateLayout());
5454
}
5555

56+
/** @override */
57+
disconnect() {
58+
if (!this.isConnected) {
59+
return;
60+
}
61+
62+
super.disconnect();
63+
64+
const { host } = this;
65+
host.$.layout.style.removeProperty('opacity');
66+
[...host.children].forEach((child) => {
67+
child.style.removeProperty('width');
68+
child.style.removeProperty('margin-left');
69+
child.style.removeProperty('margin-right');
70+
child.removeAttribute('label-position');
71+
});
72+
}
73+
5674
/** @override */
5775
setProps(props) {
5876
const { responsiveSteps } = props;
@@ -206,6 +224,10 @@ export class ResponsiveStepsLayout extends AbstractLayout {
206224

207225
/** @private */
208226
__selectResponsiveStep() {
227+
if (!this.isConnected) {
228+
return;
229+
}
230+
209231
const { host, props } = this;
210232
// Iterate through responsiveSteps and choose the step
211233
let selectedStep;

packages/form-layout/test/dom/__snapshots__/form-layout.test.snap.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,56 @@ snapshots["vaadin-form-layout defaultAutoResponsiveFormLayout feature flag defau
308308
`;
309309
/* end snapshot vaadin-form-layout defaultAutoResponsiveFormLayout feature flag default */
310310

311+
snapshots["vaadin-form-layout responsive-steps host default"] =
312+
`<vaadin-form-layout>
313+
<input
314+
placeholder="First name"
315+
style="width: calc(50% - 1em); margin-left: 0px;"
316+
>
317+
<input
318+
placeholder="Last name"
319+
style="width: calc(50% - 1em); margin-right: 0px;"
320+
>
321+
</vaadin-form-layout>
322+
`;
323+
/* end snapshot vaadin-form-layout responsive-steps host default */
324+
325+
snapshots["vaadin-form-layout responsive-steps host switching to autoResponsive"] =
326+
`<vaadin-form-layout
327+
auto-responsive=""
328+
style="--_column-width: 13em; --_max-columns: 1;"
329+
>
330+
<input
331+
placeholder="First name"
332+
style=""
333+
>
334+
<input
335+
placeholder="Last name"
336+
style=""
337+
>
338+
</vaadin-form-layout>
339+
`;
340+
/* end snapshot vaadin-form-layout responsive-steps host switching to autoResponsive */
341+
342+
snapshots["vaadin-form-layout responsive-steps shadow default"] =
343+
`<div
344+
id="layout"
345+
style=""
346+
>
347+
<slot id="slot">
348+
</slot>
349+
</div>
350+
`;
351+
/* end snapshot vaadin-form-layout responsive-steps shadow default */
352+
353+
snapshots["vaadin-form-layout responsive-steps shadow switching to autoResponsive"] =
354+
`<div
355+
id="layout"
356+
style="--_grid-rendered-column-count: 1;"
357+
>
358+
<slot id="slot">
359+
</slot>
360+
</div>
361+
`;
362+
/* end snapshot vaadin-form-layout responsive-steps shadow switching to autoResponsive */
363+

packages/form-layout/test/dom/form-layout.test.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@vaadin/chai-plugins';
2-
import { fixtureSync, nextResize } from '@vaadin/testing-helpers';
2+
import { fixtureSync, nextFrame, nextResize } from '@vaadin/testing-helpers';
33
import '../../src/vaadin-form-layout.js';
44

55
const DEFAULT_COLUMN_WIDTH = '12em';
@@ -161,4 +161,41 @@ describe('vaadin-form-layout', () => {
161161
await expect(layout).dom.to.equalSnapshot();
162162
});
163163
});
164+
165+
describe('responsive-steps', () => {
166+
beforeEach(async () => {
167+
layout = fixtureSync(`
168+
<vaadin-form-layout>
169+
<input placeholder="First name" />
170+
<input placeholder="Last name" />
171+
</vaadin-form-layout>
172+
`);
173+
layout.responsiveSteps = [{ columns: 2, labelsPosition: 'top' }];
174+
await nextFrame();
175+
});
176+
177+
describe('host', () => {
178+
it('default', async () => {
179+
await expect(layout).dom.to.equalSnapshot();
180+
});
181+
182+
it('switching to autoResponsive', async () => {
183+
layout.autoResponsive = true;
184+
await nextResize(layout);
185+
await expect(layout).dom.to.equalSnapshot();
186+
});
187+
});
188+
189+
describe('shadow', () => {
190+
it('default', async () => {
191+
await expect(layout).shadowDom.to.equalSnapshot();
192+
});
193+
194+
it('switching to autoResponsive', async () => {
195+
layout.autoResponsive = true;
196+
await nextResize(layout);
197+
await expect(layout).shadowDom.to.equalSnapshot();
198+
});
199+
});
200+
});
164201
});

0 commit comments

Comments
 (0)