-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add layout improvements behind feature flag (#8552)
* add style fixes behind feature flag * add tests * use data attribute for targeting * remove usage of unsafeCSS * simplify accessing children in tests * Apply suggestions from code review Co-authored-by: Serhii Kulykov <iamkulykov@gmail.com> * update data attribute names * Update packages/horizontal-layout/src/vaadin-horizontal-layout-styles.js * Update packages/vertical-layout/src/vaadin-vertical-layout-styles.js * Update vaadin-horizontal-layout-styles.js * update feature flag name * use auto-generated lit tests --------- Co-authored-by: Serhii Kulykov <iamkulykov@gmail.com>
- Loading branch information
1 parent
f047f75
commit fa0c544
Showing
10 changed files
with
276 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/horizontal-layout/test/enable-layout-improvements.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
window.Vaadin ??= {}; | ||
window.Vaadin.featureFlags ??= {}; | ||
window.Vaadin.featureFlags.layoutComponentImprovements = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
packages/horizontal-layout/test/layout-improvements.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { expect } from '@vaadin/chai-plugins'; | ||
import { fixtureSync, nextFrame } from '@vaadin/testing-helpers'; | ||
import './enable-layout-improvements.js'; | ||
import '../vaadin-horizontal-layout.js'; | ||
|
||
describe('layout improvements enabled', () => { | ||
let layout, children; | ||
|
||
describe('flex', () => { | ||
beforeEach(async () => { | ||
layout = fixtureSync(` | ||
<vaadin-horizontal-layout> | ||
<div></div> | ||
<div data-width-full></div> | ||
</vaadin-horizontal-layout> | ||
`); | ||
children = Array.from(layout.children); | ||
await nextFrame(); | ||
}); | ||
|
||
it('should set flex on full width children only', () => { | ||
const fullWidthChildren = children.filter((child) => child.hasAttribute('data-width-full')); | ||
const remainingChildren = children.filter((child) => !fullWidthChildren.includes(child)); | ||
|
||
fullWidthChildren.forEach((child) => { | ||
expect(getComputedStyle(child).flex).to.equal('1 1 0%'); | ||
}); | ||
remainingChildren.forEach((child) => { | ||
expect(getComputedStyle(child).flex).to.equal('0 1 auto'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('min-width', () => { | ||
beforeEach(async () => { | ||
layout = fixtureSync(` | ||
<vaadin-horizontal-layout> | ||
<div></div> | ||
<div data-width-full></div> | ||
<vaadin-button></vaadin-button> | ||
<vaadin-button data-width-full></vaadin-button> | ||
<vaadin-horizontal-layout></vaadin-horizontal-layout> | ||
<vaadin-horizontal-layout data-width-full></vaadin-horizontal-layout> | ||
<vaadin-vertical-layout></vaadin-vertical-layout> | ||
<vaadin-vertical-layout data-width-full></vaadin-vertical-layout> | ||
</vaadin-horizontal-layout> | ||
`); | ||
children = Array.from(layout.children); | ||
await nextFrame(); | ||
}); | ||
|
||
it('should set min-width on layout components with full width only', () => { | ||
const layoutChildren = children.filter( | ||
(child) => child.localName.endsWith('layout') && child.hasAttribute('data-width-full'), | ||
); | ||
const remainingChildren = children.filter((child) => !layoutChildren.includes(child)); | ||
|
||
layoutChildren.forEach((child) => { | ||
expect(getComputedStyle(child).minWidth).to.equal('0px'); | ||
}); | ||
|
||
remainingChildren.forEach((child) => { | ||
expect(getComputedStyle(child).minWidth).to.equal('auto'); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
window.Vaadin ??= {}; | ||
window.Vaadin.featureFlags ??= {}; | ||
window.Vaadin.featureFlags.layoutComponentImprovements = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { expect } from '@vaadin/chai-plugins'; | ||
import { fixtureSync, nextFrame } from '@vaadin/testing-helpers'; | ||
import './enable-layout-improvements.js'; | ||
import '../vaadin-vertical-layout.js'; | ||
|
||
describe('layout improvements enabled', () => { | ||
let layout, children; | ||
|
||
describe('flex', () => { | ||
beforeEach(async () => { | ||
layout = fixtureSync(` | ||
<vaadin-vertical-layout> | ||
<div></div> | ||
<div data-height-full></div> | ||
</vaadin-vertical-layout> | ||
`); | ||
children = Array.from(layout.children); | ||
await nextFrame(); | ||
}); | ||
|
||
it('should set flex on full height children only', () => { | ||
const fullHeightChildren = children.filter((child) => child.hasAttribute('data-height-full')); | ||
const remainingChildren = children.filter((child) => !fullHeightChildren.includes(child)); | ||
|
||
fullHeightChildren.forEach((child) => { | ||
expect(getComputedStyle(child).flex).to.equal('1 1 0%'); | ||
}); | ||
remainingChildren.forEach((child) => { | ||
expect(getComputedStyle(child).flex).to.equal('0 1 auto'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('min-height', () => { | ||
beforeEach(async () => { | ||
layout = fixtureSync(` | ||
<vaadin-vertical-layout> | ||
<div></div> | ||
<div data-height-full></div> | ||
<vaadin-button></vaadin-button> | ||
<vaadin-button data-height-full></vaadin-button> | ||
<vaadin-horizontal-layout></vaadin-horizontal-layout> | ||
<vaadin-horizontal-layout data-height-full></vaadin-horizontal-layout> | ||
<vaadin-vertical-layout></vaadin-vertical-layout> | ||
<vaadin-vertical-layout data-height-full></vaadin-vertical-layout> | ||
</vaadin-vertical-layout> | ||
`); | ||
children = Array.from(layout.children); | ||
await nextFrame(); | ||
}); | ||
|
||
it('should set min-height on layout components with full height only', () => { | ||
const layoutChildren = children.filter( | ||
(child) => child.localName.endsWith('layout') && child.hasAttribute('data-height-full'), | ||
); | ||
const remainingChildren = children.filter((child) => !layoutChildren.includes(child)); | ||
|
||
layoutChildren.forEach((child) => { | ||
expect(getComputedStyle(child).minHeight).to.equal('0px'); | ||
}); | ||
|
||
remainingChildren.forEach((child) => { | ||
expect(getComputedStyle(child).minHeight).to.equal('auto'); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters