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

feat: add form layout row spacing, deprecate form item row spacing #8624

Merged
15 changes: 15 additions & 0 deletions packages/form-layout/src/vaadin-form-item-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import { addValueToAttribute, removeValueFromAttribute } from '@vaadin/component-base/src/dom-utils.js';
import { generateUniqueId } from '@vaadin/component-base/src/unique-id-utils.js';

let itemRowSpacingDeprecationNotified = false;

/**
* @polymerMixin
*/
Expand Down Expand Up @@ -42,6 +44,19 @@ export const FormItemMixin = (superClass) =>
this.__fieldNode = null;
}

connectedCallback() {
super.connectedCallback();
if (!itemRowSpacingDeprecationNotified) {
const spacing = getComputedStyle(this).getPropertyValue('--vaadin-form-item-row-spacing');
if (spacing !== '' && parseInt(spacing) !== 0) {
console.warn(
'`--vaadin-form-item-row-spacing` is deprecated since 24.7. Use `--vaadin-form-layout-row-spacing` on <vaadin-form-layout> instead.',
);
itemRowSpacingDeprecationNotified = true;
}
}
}

/**
* Returns a target element to add ARIA attributes to for a field.
*
Expand Down
4 changes: 2 additions & 2 deletions packages/form-layout/src/vaadin-form-layout-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const formLayoutStyles = css`
/* CSS API for host */
--vaadin-form-item-label-width: 8em;
--vaadin-form-item-label-spacing: 1em;
--vaadin-form-item-row-spacing: 1em;
--vaadin-form-layout-row-spacing: 1em;
--vaadin-form-layout-column-spacing: 2em; /* (default) */
align-self: stretch;
}
Expand Down Expand Up @@ -49,7 +49,7 @@ export const formItemStyles = css`
display: inline-flex;
flex-direction: row;
align-items: baseline;
margin: calc(0.5 * var(--vaadin-form-item-row-spacing, 1em)) 0;
margin: calc(0.5 * var(--vaadin-form-item-row-spacing, var(--vaadin-form-layout-row-spacing, 1em))) 0;
}

:host([label-position='top']) {
Expand Down
16 changes: 15 additions & 1 deletion packages/form-layout/test/form-layout.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,25 @@ describe('form layout', () => {
});

it('should not have default row-spacing', () => {
expect(getComputedStyle(item).getPropertyValue('--vaadin-form-item-row-spacing').trim()).to.equal('0');
expect(getComputedStyle(item).getPropertyValue('--vaadin-form-layout-row-spacing').trim()).to.equal('0');
expect(parseFloat(getComputedStyle(item).marginTop)).to.equal(0);
expect(parseFloat(getComputedStyle(item).marginBottom)).to.equal(0);
});

it('should apply form layout row spacing', () => {
const spacing = 8;
item.style.setProperty('--vaadin-form-layout-row-spacing', `${spacing}px`);
expect(parseFloat(getComputedStyle(item).marginTop)).to.equal(spacing / 2);
expect(parseFloat(getComputedStyle(item).marginBottom)).to.equal(spacing / 2);
});

it('should apply form item row spacing', () => {
const spacing = 8;
item.style.setProperty('--vaadin-form-item-row-spacing', `${spacing}px`);
expect(parseFloat(getComputedStyle(item).marginTop)).to.equal(spacing / 2);
expect(parseFloat(getComputedStyle(item).marginBottom)).to.equal(spacing / 2);
});

it('should apply default column-spacing', async () => {
// Override to not depend on the theme changes
layout.style.setProperty('--lumo-space-l', '2rem');
Expand Down
4 changes: 0 additions & 4 deletions packages/form-layout/theme/lumo/vaadin-form-item-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themab
registerStyles(
'vaadin-form-item',
css`
:host {
--vaadin-form-item-row-spacing: 0;
}

/* font-weight, margin-bottom, transition and line-height same as for part label in text-field */
[part='label'] {
color: var(--lumo-secondary-text-color);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ registerStyles(
css`
:host {
--vaadin-form-layout-column-spacing: var(--lumo-space-l);
--vaadin-form-layout-row-spacing: 0;
}
`,
{ moduleId: 'lumo-form-layout' },
Expand Down