Skip to content

Commit 106c38e

Browse files
authoredMar 25, 2025
refactor: preserve mode when adding or removing details (#8855)
1 parent 1649a17 commit 106c38e

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed
 

‎packages/master-detail-layout/src/vaadin-master-detail-layout.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -383,30 +383,27 @@ class MasterDetailLayout extends ResizeMixin(ElementMixin(ThemableMixin(PolylitM
383383

384384
/** @private */
385385
__detectLayoutMode() {
386-
if (!this.hasAttribute('has-detail')) {
387-
this.removeAttribute('overlay');
388-
this.removeAttribute('stack');
389-
return;
390-
}
386+
this.removeAttribute('overlay');
387+
this.removeAttribute('stack');
391388

392389
if (this.forceOverlay) {
393-
this.removeAttribute('stack');
394390
this.setAttribute('overlay', '');
395391
return;
396392
}
397393

398394
if (this.stackThreshold != null) {
399-
this.removeAttribute('stack');
400-
401395
const threshold = this.__getStackThresholdInPixels();
402396
const size = this.orientation === 'vertical' ? this.offsetHeight : this.offsetWidth;
403397
if (size <= threshold) {
404-
this.removeAttribute('overlay');
405398
this.setAttribute('stack', '');
406399
return;
407400
}
408401
}
409402

403+
if (!this.hasAttribute('has-detail')) {
404+
return;
405+
}
406+
410407
if (this.orientation === 'vertical') {
411408
this.__detectVerticalMode();
412409
} else {

‎packages/master-detail-layout/test/master-detail-layout.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ describe('vaadin-master-detail-layout', () => {
215215
expect(getComputedStyle(detail).width).to.equal('450px');
216216
});
217217

218-
it('should update stack mode when adding and removing details', async () => {
218+
it('should preserve the stack mode when adding and removing details', async () => {
219219
layout.stackThreshold = '500px';
220220

221221
// Start without details
@@ -226,7 +226,7 @@ describe('vaadin-master-detail-layout', () => {
226226
await setViewport({ width: 450, height });
227227
await nextResize(layout);
228228

229-
expect(layout.hasAttribute('stack')).to.be.false;
229+
expect(layout.hasAttribute('stack')).to.be.true;
230230

231231
// Add details
232232
layout.appendChild(detailContent);
@@ -238,7 +238,7 @@ describe('vaadin-master-detail-layout', () => {
238238
detailContent.remove();
239239
await nextRender();
240240

241-
expect(layout.hasAttribute('stack')).to.be.false;
241+
expect(layout.hasAttribute('stack')).to.be.true;
242242
});
243243

244244
it('should focus detail content when adding details in the stack mode', async () => {

‎packages/master-detail-layout/test/overlay-mode.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,14 @@ describe('overlay mode', () => {
180180
expect(layout.hasAttribute('overlay')).to.be.false;
181181
});
182182

183-
it('should not set the overlay mode with forceOverlay after removing details', async () => {
183+
it('should preserve the overlay mode with forceOverlay after removing details', async () => {
184184
layout.forceOverlay = true;
185185
await nextRender();
186186

187187
detailContent.remove();
188188
await nextRender();
189189

190-
expect(layout.hasAttribute('overlay')).to.be.false;
190+
expect(layout.hasAttribute('overlay')).to.be.true;
191191

192192
layout.appendChild(detailContent);
193193
await nextRender();

0 commit comments

Comments
 (0)