Skip to content

Commit ba37cd3

Browse files
authored
feat: add expandColumns support to autoResponsive mode (#8749)
1 parent 674c2b1 commit ba37cd3

16 files changed

+126
-1
lines changed

packages/form-layout/src/vaadin-form-layout-mixin.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ export declare class FormLayoutMixinClass {
123123
*/
124124
labelsAside: boolean;
125125

126+
/**
127+
* When `autoResponsive` is enabled, specifies whether the columns should expand
128+
* in width to evenly fill any remaining space after the layout has created as
129+
* many fixed-width (`columnWidth`) columns as possible within the `maxColumns`
130+
* limit. The default value is `false`.
131+
*
132+
* @attr {boolean} expand-columns
133+
*/
134+
expandColumns: boolean;
135+
126136
/**
127137
* Update the layout.
128138
*/

packages/form-layout/src/vaadin-form-layout-mixin.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,21 @@ export const FormLayoutMixin = (superClass) =>
166166
reflectToAttribute: true,
167167
},
168168

169+
/**
170+
* When `autoResponsive` is enabled, specifies whether the columns should expand
171+
* in width to evenly fill any remaining space after the layout has created as
172+
* many fixed-width (`columnWidth`) columns as possible within the `maxColumns`
173+
* limit. The default value is `false`.
174+
*
175+
* @attr {boolean} expand-columns
176+
*/
177+
expandColumns: {
178+
type: Boolean,
179+
sync: true,
180+
value: false,
181+
reflectToAttribute: true,
182+
},
183+
169184
/**
170185
* Current number of columns in the layout
171186
* @private

packages/form-layout/src/vaadin-form-layout-styles.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ export const formLayoutStyles = css`
5959
--_grid-column-width: var(--_column-width-labels-above);
6060
--_grid-column-max-total-gap: calc((var(--_max-columns) - 1) * var(--_grid-column-gap));
6161
--_grid-column-max-total-width: calc(var(--_max-columns) * var(--_column-width-labels-above));
62+
--_grid-repeat: var(--_grid-column-width);
6263
6364
display: grid;
64-
grid-template-columns: repeat(auto-fit, var(--_grid-column-width));
65+
grid-template-columns: repeat(auto-fit, var(--_grid-repeat));
6566
justify-items: start;
6667
gap: var(--vaadin-form-layout-row-spacing) var(--_grid-column-gap);
6768
@@ -94,6 +95,7 @@ export const formLayoutStyles = css`
9495
--_form-item-labels-above: initial; /* true */
9596
--_form-item-labels-aside: ' '; /* false */
9697
98+
/* By default, place each child on a new row */
9799
grid-column-start: 1;
98100
}
99101
@@ -113,6 +115,24 @@ export const formLayoutStyles = css`
113115
--_form-item-labels-above: ' '; /* false */
114116
--_form-item-labels-aside: initial; /* true */
115117
}
118+
119+
:host([auto-responsive][expand-columns]) #layout {
120+
/*
121+
The "min" value in minmax ensures that once "maxColumns" is reached, the grid stops adding
122+
new columns and instead expands the existing ones evenly to fill the available space.
123+
124+
The "max" value in minmax allows CSS grid columns to grow and evenly distribute any space
125+
that remains when there isn't room for an additional column and "maxColumns" hasn't been
126+
reached yet.
127+
*/
128+
--_grid-repeat: minmax(
129+
max(var(--_grid-column-width), calc((100% - var(--_grid-column-max-total-gap)) / var(--_max-columns))),
130+
1fr
131+
);
132+
133+
/* Allow the layout to take up full available width of the parent element. */
134+
flex-grow: 1;
135+
}
116136
`;
117137

118138
export const formRowStyles = css`

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ snapshots["vaadin-form-layout auto-responsive basic host labelsAside"] =
5454
`;
5555
/* end snapshot vaadin-form-layout auto-responsive basic host labelsAside */
5656

57+
snapshots["vaadin-form-layout auto-responsive basic host expandColumns"] =
58+
`<vaadin-form-layout
59+
auto-responsive=""
60+
expand-columns=""
61+
style="--_column-width: 13em; --_max-columns: 10;"
62+
>
63+
<input placeholder="First name">
64+
<input placeholder="Last name">
65+
<input placeholder="Email">
66+
<input placeholder="Phone">
67+
</vaadin-form-layout>
68+
`;
69+
/* end snapshot vaadin-form-layout auto-responsive basic host expandColumns */
70+
5771
snapshots["vaadin-form-layout auto-responsive basic shadow default"] =
5872
`<div id="layout">
5973
<slot id="slot">

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ describe('vaadin-form-layout', () => {
3939
await nextResize(layout);
4040
await expect(layout).dom.to.equalSnapshot();
4141
});
42+
43+
it('expandColumns', async () => {
44+
layout.expandColumns = true;
45+
await expect(layout).dom.to.equalSnapshot();
46+
});
4247
});
4348

4449
describe('shadow', () => {

packages/form-layout/test/typings/form-layout.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ assertType<boolean>(layout.autoResponsive);
1717
assertType<string>(layout.columnWidth);
1818
assertType<number>(layout.maxColumns);
1919
assertType<boolean>(layout.autoRows);
20+
assertType<boolean>(layout.expandColumns);
2021

2122
assertType<string | 0 | undefined>(responsiveSteps.minWidth);
2223
assertType<number | undefined>(responsiveSteps.columns);

packages/form-layout/test/visual/lumo/form-layout-auto-responsive.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,20 @@ describe('form-layout auto responsive', () => {
184184
await visualDiff(container, 'form-items');
185185
});
186186

187+
it('expandColumns in narrow container', async () => {
188+
container.style.width = `calc(${element.columnWidth} + 6em)`;
189+
element.expandColumns = true;
190+
await nextResize(element);
191+
await visualDiff(container, 'form-items-expand-columns-narrow-container');
192+
});
193+
194+
it('expandColumns in wide container', async () => {
195+
container.style.width = '50em';
196+
element.expandColumns = true;
197+
await nextResize(element);
198+
await visualDiff(container, 'form-items-expand-columns-wide-container');
199+
});
200+
187201
it('labelsAside in narrow container', async () => {
188202
container.style.width = `calc(${element.columnWidth} + 6em)`;
189203
element.labelsAside = true;
@@ -198,6 +212,22 @@ describe('form-layout auto responsive', () => {
198212
await visualDiff(container, 'form-items-labels-aside-wide-container');
199213
});
200214

215+
it('labelsAside + expandColumns in narrow container', async () => {
216+
container.style.width = `calc(${element.columnWidth} + 6em)`;
217+
element.labelsAside = true;
218+
element.expandColumns = true;
219+
await nextResize(element);
220+
await visualDiff(container, 'form-items-labels-aside-expand-columns-narrow-container');
221+
});
222+
223+
it('labelsAside + expandColumns in wide container', async () => {
224+
container.style.width = '50em';
225+
element.labelsAside = true;
226+
element.expandColumns = true;
227+
await nextResize(element);
228+
await visualDiff(container, 'form-items-labels-aside-expand-columns-wide-container');
229+
});
230+
201231
it('labelsAside + custom CSS properties', async () => {
202232
element.labelsAside = true;
203233
element.style.setProperty('--vaadin-form-layout-label-width', '200px');
4.72 KB
Loading
4.18 KB
Loading
4.72 KB
Loading

0 commit comments

Comments
 (0)