Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(FormLayout): do not ignore labelsAside when using explicit rows #8760

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions packages/form-layout/src/vaadin-form-layout-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export const formLayoutStyles = css`
}

:host([auto-responsive]) #layout {
/* By default, labels should be displayed above the fields */
--_form-item-labels-above: initial; /* true */
--_form-item-labels-aside: ' '; /* false */

/* CSS grid related properties */
--_grid-column-gap: var(--vaadin-form-layout-column-spacing);
--_grid-column-width: var(--_column-width-labels-above);
--_grid-column-max-total-gap: calc((var(--_max-columns) - 1) * var(--_grid-column-gap));
Expand Down Expand Up @@ -100,8 +105,9 @@ export const formLayoutStyles = css`
}

:host([auto-responsive]) #layout ::slotted(*) {
--_form-item-labels-above: initial; /* true */
--_form-item-labels-aside: ' '; /* false */
/* Make form items inherit label position from the layout */
--_form-item-labels-above: unset;
--_form-item-labels-aside: unset;

/* By default, place each child on a new row */
grid-column: 1 / span min(var(--_grid-colspan, 1), var(--_grid-rendered-column-count));
Expand All @@ -116,12 +122,9 @@ export const formLayoutStyles = css`
}

:host([auto-responsive][labels-aside]) #layout[fits-labels-aside] {
--_grid-column-width: var(--_column-width-labels-aside);
}

:host([auto-responsive][labels-aside]) #layout[fits-labels-aside] ::slotted(*) {
--_form-item-labels-above: ' '; /* false */
--_form-item-labels-aside: initial; /* true */
--_grid-column-width: var(--_column-width-labels-aside);
}

:host([auto-responsive][expand-columns]) #layout {
Expand Down Expand Up @@ -153,6 +156,10 @@ export const formRowStyles = css`
}

::slotted(*) {
/* Make form items inherit label position from the layout */
--_form-item-labels-above: unset;
--_form-item-labels-aside: unset;

grid-column: auto / span min(var(--_grid-colspan, 1), var(--_grid-rendered-column-count));
}

Expand All @@ -163,6 +170,7 @@ export const formRowStyles = css`

export const formItemStyles = css`
:host {
/* By default, when auto-responsive mode is disabled, labels should be displayed beside the fields. */
--_form-item-labels-above: ' '; /* false */
--_form-item-labels-aside: initial; /* true */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,50 @@ describe('form-layout auto responsive', () => {
});
});

describe('form items with explicit rows', () => {
beforeEach(async () => {
element = fixtureSync(
`
<vaadin-form-layout auto-responsive>
<vaadin-form-row>
<vaadin-form-item>
<label slot="label">First name</label>
<input />
</vaadin-form-item>
<vaadin-form-item>
<label slot="label">Last name</label>
<input />
</vaadin-form-item>
</vaadin-form-row>

<vaadin-form-row>
<vaadin-form-item>
<label slot="label">Email</label>
<input />
</vaadin-form-item>
<vaadin-form-item>
<label slot="label">Phone</label>
<input />
</vaadin-form-item>
</vaadin-form-row>
</vaadin-form-layout>
`,
container,
);
await nextFrame();
});

it('default', async () => {
await visualDiff(container, 'form-items-with-explicit-rows');
});

it('labelsAside', async () => {
element.labelsAside = true;
await nextResize(element);
await visualDiff(container, 'form-items-with-explicit-rows-labels-aside');
});
});

describe('colspan', () => {
beforeEach(async () => {
element = fixtureSync(
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,50 @@ describe('form-layout auto responsive', () => {
});
});

describe('form items with explicit rows', () => {
beforeEach(async () => {
element = fixtureSync(
`
<vaadin-form-layout auto-responsive>
<vaadin-form-row>
<vaadin-form-item>
<label slot="label">First name</label>
<input />
</vaadin-form-item>
<vaadin-form-item>
<label slot="label">Last name</label>
<input />
</vaadin-form-item>
</vaadin-form-row>

<vaadin-form-row>
<vaadin-form-item>
<label slot="label">Email</label>
<input />
</vaadin-form-item>
<vaadin-form-item>
<label slot="label">Phone</label>
<input />
</vaadin-form-item>
</vaadin-form-row>
</vaadin-form-layout>
`,
container,
);
await nextFrame();
});

it('default', async () => {
await visualDiff(container, 'form-items-with-explicit-rows');
});

it('labelsAside', async () => {
element.labelsAside = true;
await nextResize(element);
await visualDiff(container, 'form-items-with-explicit-rows-labels-aside');
});
});

describe('colspan', () => {
beforeEach(async () => {
element = fixtureSync(
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.