Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
22 changes: 22 additions & 0 deletions packages/form-layout/src/styles/vaadin-form-item-base-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,30 @@ export const formItemStyles = css`
font-size: var(--vaadin-form-item-label-font-size, inherit);
font-weight: var(--vaadin-form-item-label-font-weight, 500);
line-height: var(--vaadin-form-item-label-line-height, inherit);
position: relative;
width: var(--_form-item-labels-aside, var(--_label-width, 8em));
word-break: break-word;
box-sizing: border-box;
}

:host([required]) [part='label'] {
padding-inline-end: 1em;
}

[part='required-indicator'] {
display: inline-block;
position: absolute;
width: 1em;
text-align: center;
color: var(--vaadin-input-field-required-indicator-color, var(--vaadin-text-color-secondary));
}

[part='required-indicator']::after {
content: var(--vaadin-input-field-required-indicator, '*');
}

:host(:not([required])) [part='required-indicator'] {
display: none;
}

#spacing {
Expand Down
41 changes: 41 additions & 0 deletions packages/form-layout/test/visual/aura/form-layout.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { nextFrame } from '@vaadin/testing-helpers';
import { fixtureSync } from '@vaadin/testing-helpers/dist/fixture.js';
import { visualDiff } from '@web/test-runner-visual-regression';
import '@vaadin/aura/aura.css';
Expand Down Expand Up @@ -50,4 +51,44 @@ describe('form-layout', () => {
await visualDiff(element, 'basic');
});
});

describe('required indicator', () => {
beforeEach(async () => {
element = fixtureSync(`
<vaadin-form-layout>
<vaadin-form-item>
<label slot="label">First Name</label>
<input required value="Jane" />
</vaadin-form-item>

<vaadin-form-item>
<label slot="label">Last Name</label>
<input required />
</vaadin-form-item>

<vaadin-form-item>
<label slot="label">Email</label>
<input required value="jane.doe@example.com" />
</vaadin-form-item>
</vaadin-form-layout>
`);

await nextFrame();

// Make the second input validate so that it becomes invalid
element.querySelectorAll('input')[1].dispatchEvent(new CustomEvent('change'));
});

it('required indicator - labels aside', async () => {
await visualDiff(element, 'required-indicator-labels-aside');
});

it('required-indicator - labels on top', async () => {
element.responsiveSteps = element.responsiveSteps.map((step) => {
step.labelsPosition = 'top';
return step;
});
await visualDiff(element, 'required-indicator-labels-on-top');
});
});
});
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.
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.
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.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the visual test where the change described in this review comment would be most noticeable. The checkbox in the last row would render without any spacing from the one above it.

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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 1 addition & 9 deletions packages/vaadin-lumo-styles/src/components/form-item.css
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure which approach would be better for the Lumo theme:

  1. Add styles to override the base style changes
  2. Adopt the base styles in Lumo, accepting the minor visual differences

I went with (2). The min-height: 1lh on [part=label] is meant to mitigate the layout shift that a label-less <vaadin-form-item> would otherwise have.

Previously in Lumo, the [part=required-indicator] pseudo-element only had its opacity toggled, meaning its intrinsic size still contributed to the [part=label] layout even when no [required] attribute was set on the field component. The new approach toggles display instead, which means that when the field is not required, a <vaadin-form-item> without a label will collapse closer to the line above.

Arguably, this is a side effect of the current styling implementation, and users should define their own spacing. However, it could be perceived as a breaking change if the spacing is suddenly removed in that scenario.

Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,15 @@
margin-left: calc(var(--lumo-border-radius-m) / 4);
margin-bottom: var(--lumo-space-xs);
line-height: 1.333;
min-height: 1lh;
}

[part='required-indicator']::after {
content: var(--vaadin-input-field-required-indicator, var(--lumo-required-field-indicator, '\2022'));
transition: opacity 0.2s;
opacity: 0;
color: var(
--vaadin-input-field-required-indicator-color,
var(--lumo-required-field-indicator-color, var(--lumo-primary-text-color))
);
position: relative;
width: 1em;
text-align: center;
}

:host([required]) [part='required-indicator']::after {
opacity: 1;
}

:host([invalid]) [part='required-indicator']::after {
Expand Down
Loading