Skip to content

Commit

Permalink
fix: do not update form-layout when it is not visible (#7792)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Sep 11, 2024
1 parent 554b1e1 commit 7dcd7cb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/form-layout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
],
"dependencies": {
"@polymer/polymer": "^3.0.0",
"@vaadin/a11y-base": "24.5.0-alpha11",
"@vaadin/component-base": "24.5.0-alpha11",
"@vaadin/vaadin-lumo-styles": "24.5.0-alpha11",
"@vaadin/vaadin-material-styles": "24.5.0-alpha11",
Expand Down
6 changes: 6 additions & 0 deletions packages/form-layout/src/vaadin-form-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
import { isElementHidden } from '@vaadin/a11y-base/src/focus-utils.js';
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
import { ResizeMixin } from '@vaadin/component-base/src/resize-mixin.js';
Expand Down Expand Up @@ -456,6 +457,11 @@ class FormLayout extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement))
* @protected
*/
_updateLayout() {
// Do not update layout when invisible
if (isElementHidden(this)) {
return;
}

/*
The item width formula:
Expand Down
9 changes: 9 additions & 0 deletions packages/form-layout/test/form-layout.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,5 +627,14 @@ describe('form layout', () => {
await nextRender(container);
expect(getComputedStyle(itemsList[1]).marginLeft).to.be.equal('0px');
});

it('should not update layout when setting hidden to true', async () => {
const percent = getParsedWidth(layout.firstElementChild).percentage;

container.hidden = true;
await nextRender();

expect(getParsedWidth(layout.firstElementChild).percentage).to.be.equal(percent);
});
});
});

0 comments on commit 7dcd7cb

Please sign in to comment.