Skip to content

Commit b37f61f

Browse files
vursenjounirusselljtdyer
authored
docs: document FormLayout style properties (vaadin#3573)
* docs: document FormLayout style properties * change order of table rows * alternative wording * Update articles/components/form-layout/index.adoc * simplify wording * limit since to only Flow * Update articles/components/form-layout/index.adoc Co-authored-by: Jouni Koivuviita <[email protected]> * Editing changed text and some minor items. * Full editing of document touched. * Second pass at full editing of document touched. --------- Co-authored-by: Jouni Koivuviita <[email protected]> Co-authored-by: russelljtdyer <[email protected]>
1 parent 0054d7e commit b37f61f

File tree

4 files changed

+53
-22
lines changed

4 files changed

+53
-22
lines changed

articles/components/form-layout/index.adoc

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
tab-title: Usage
33
title: Form Layout
4-
description: Form Layout allows you to build responsive forms with multiple columns, and to position input labels above or to the side of the input.
4+
description: Using Form Layout to build responsive forms with multiple columns and better positioned input labels.
55
page-links:
66
- 'API: https://cdn.vaadin.com/vaadin-web-components/{moduleNpmVersion:@vaadin/form-layout}/#/elements/vaadin-form-layout[TypeScript] / https://vaadin.com/api/platform/{moduleMavenVersion:com.vaadin:vaadin}/com/vaadin/flow/component/formlayout/FormLayout.html[Java]'
77
- 'Source: https://github.com/vaadin/web-components/tree/v{moduleNpmVersion:@vaadin/form-layout}/packages/form-layout[TypeScript] / https://github.com/vaadin/flow-components/tree/{moduleMavenVersion:com.vaadin:vaadin}/vaadin-form-layout-flow-parent[Java]'
@@ -39,16 +39,15 @@ include::{root}/frontend/demo/component/formlayout/react/form-layout-basic.tsx[r
3939
endif::[]
4040
--
4141

42+
4243
== Columns
4344

44-
By default, Form Layout has two columns, meaning it displays two input fields per line. When the layout width is smaller, it adjusts to a single-column.
45+
By default, Form Layout has two columns: it displays two input fields per line. When the layout width is smaller, it adjusts to a single-column.
4546

46-
=== Custom Layout
4747

48-
You can define how many columns Form Layout should use based on the screen width.
48+
=== Custom Layout
4949

50-
[IMPORTANT]
51-
Use the draggable split handle to resize Form Layout's available space and to test its responsiveness.
50+
You can define how many columns that Form Layout should use based on the screen width. Use the draggable split handle to resize Form Layout's available space and to test its responsiveness.
5251

5352
[.example]
5453
--
@@ -75,16 +74,14 @@ include::{root}/frontend/demo/component/formlayout/react/form-layout-custom-layo
7574
endif::[]
7675
--
7776

78-
A single-column layout is preferable to a multi-column one. A multi-column layout can be prone to confusion and misinterpretation by the user.
79-
80-
However, related fields can be placed in a line without confusion, typically. Examples of this would be first and last name, address fields such as postal code and city, and ranged input for dates, time, and currency.
77+
A single-column layout is preferable to a multi-column layout. A multi-column layout can be prone to confusion and misinterpretation by the user. However, related fields placed in a line are typically understandable. Examples of this would be first and last name, address fields such as city and postal code, and ranged input for dates, time, and price or cost.
8178

8279

8380
=== Column Span
8481

8582
When using a multi-column layout, you can define a `colspan` for each component. The `colspan` determines how many columns a component extends or stretches across.
8683

87-
For example, if you have a Form Layout with three columns and a component's `colspan` is set to 3, it takes up the entire width of the Form Layout.
84+
For example, if you have a Form Layout with three columns and a component's `colspan` is set to 3, it'll therefore take the entire width of the Form Layout.
8885

8986
[.example]
9087
--
@@ -111,23 +108,26 @@ include::{root}/frontend/demo/component/formlayout/react/form-layout-colspan.tsx
111108
endif::[]
112109
--
113110

111+
114112
== Label Position
115113

116-
Input fields' built-in labels are positioned above the input. Form Layout supports side-positioned labels, provided they are wrapped in Form Items and the label position is set to `aside`.
114+
The built-in labels for input fields are positioned above the input. Form Layout supports side-positioned labels, provided they're wrapped in Form Items and the label position is set to `aside`.
117115

118116
The only reason for wrapping labels in Form Items is to put the labels to the side of the input.
119117

118+
120119
=== Top
121120

122-
Users complete forms that have top-positioned labels more quickly because they provide a consistent scanning pattern -- top-down, as opposed to zigzag -- while minimizing the distance between the label and input.
121+
Users complete forms that have top-positioned labels more quickly because they provide a consistent scanning pattern -- top-down, as opposed to zigzag -- while minimizing the distance between the label and input field.
123122

124123
Top-positioned labels are also less prone to causing layout issues due to variable label lengths, which happens usually in multilingual applications. However, they do result in vertically longer forms. This is why <<#sectioning,sectioning>> is important.
125124

125+
126126
=== Side
127127

128128
Side-positioned labels help reduce a form's total height. This is especially useful for longer forms and when vertical space is limited.
129129

130-
Labels positioned on the side are also often used when there is a need to compare numeric data.
130+
The positioning of labels on the side is also useful when there's a need to compare numeric data.
131131

132132
[.example]
133133
--
@@ -154,14 +154,38 @@ include::{root}/frontend/demo/component/formlayout/react/form-layout-side.tsx[re
154154
endif::[]
155155
--
156156

157-
Aim for similar-length labels to keep the distance between the labels and input fields consistent. Inconsistent spacing can slow the user in completing the form.
157+
Aim for similar-length labels to keep the distance consistent between the labels and the input fields. Inconsistent spacing can slow the user in completing a form.
158+
159+
Forms that use this position require more horizontal space, which isn't always ideal in narrow forms. Instead, configure Form Layout to use top-positioned labels when the form has a narrow width.
158160

159-
Forms that use this position require more horizontal space, which isn't always ideal in narrow forms. It's recommended to configure Form Layout to use top-positioned labels when the form has a narrow width.
161+
The width of side-positioned labels can be adjusted using the `--vaadin-form-item-label-width` CSS property on the Form Layout element, or with the [since:com.vaadin:[email protected]]#[methodname]`setLabelWidth()` method# on the [classname]`FormLayout` instance in Flow.
160162

161163

162164
=== Responsive Label Position
163165

164-
Similar to the number of columns, the label position is configurable based on the width of the layout. For example, you can position the labels to the side when there is ample horizontal space available, and on top for narrower screens.
166+
Similar to the number of columns, the label position is configurable based on the width of the layout. For example, you can position the labels to the side when there's ample horizontal space available, and on top for narrower screens.
167+
168+
169+
== Spacing
170+
171+
Form Layout allows you to configure the spacing between columns, rows, and between the label and input field when labels are positioned on the side.
172+
173+
To configure the spacing, use the following CSS properties on the Form Layout element:
174+
175+
[.example]
176+
177+
|===
178+
| Property | Default Value
179+
180+
| `--vaadin-form-layout-column-spacing`
181+
| `var(--lumo-space-l)`
182+
183+
| `--vaadin-form-item-row-spacing`
184+
| `1em`
185+
186+
| `--vaadin-form-item-label-spacing`
187+
| `1em`
188+
|===
165189

166190

167191
== Native Input Fields
@@ -193,6 +217,7 @@ include::{root}/frontend/demo/component/formlayout/react/form-layout-native-inpu
193217
endif::[]
194218
--
195219

220+
196221
== Multiple Fields
197222

198223
Form Item only supports placing a single field inside. Where you need to place multiple fields, <<../custom-field#,Custom Field>> should be used as a wrapper:
@@ -222,21 +247,26 @@ include::{root}/frontend/demo/component/formlayout/react/form-layout-custom-fiel
222247
endif::[]
223248
--
224249

225-
Keeping fields in individual Form Items, however, is preferable. Wrapped fields can be hard to distinguish visually since they usually have no individual label except for a placeholder, which is only visible when the field has no value.
250+
Keeping fields in individual Form Items is preferable. Wrapped fields can be hard to distinguish visually since they usually have no individual label except for a placeholder, which is only visible when the field has no value.
251+
226252

227253
== Best Practices
228254

255+
With regards to developing with Form Layout, this section provides some suggestions for better user experiences.
256+
257+
229258
=== Sectioning
230259

231260
Longer forms should be split into smaller, more manageable and user-friendly sections using sub-headings, <<../tabs#,Tabs>>, <<../details#,Details>> or separate views when possible. Each section should consist of related content and fields.
232261

262+
233263
=== Button Placement
234264

235265
Use the following guidelines for Button placement in forms:
236266

237-
* Buttons should be placed below the form with which they are associated.
238-
* Buttons should be aligned to the left.
239-
* Primary action should be placed first, followed by other actions, in order of importance.
267+
- Buttons should be placed below the form with which they're associated.
268+
- Buttons should be aligned to the left.
269+
- Primary action should be placed first, followed by other actions, in order of importance.
240270

241271
For more information, see the <<../button#,Button documentation>>.
242272

frontend/demo/component/formlayout/form-layout-side.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class Example extends LitElement {
1919
protected override render() {
2020
return html`
2121
<!-- tag::snippet[] -->
22-
<vaadin-form-layout>
22+
<vaadin-form-layout style="--vaadin-form-item-label-width: 60px;">
2323
<!-- Wrap fields into form items, which
2424
displays labels on the side by default -->
2525
<vaadin-form-item>

frontend/demo/component/formlayout/react/form-layout-side.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { TextField } from '@vaadin/react-components/TextField.js';
77
function Example() {
88
return (
99
// tag::snippet[]
10-
<FormLayout>
10+
<FormLayout style={{ '--vaadin-form-item-label-width': '60px' }}>
1111
{/* Wrap fields into form items, which displays labels on the side by default */}
1212
<FormItem>
1313
<label slot="label">Revenue</label>

src/main/java/com/vaadin/demo/component/formlayout/FormLayoutSide.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public FormLayoutSide() {
2222

2323
FormLayout formLayout = new FormLayout();
2424
// tag::snippet[]
25+
formLayout.setLabelWidth("60px");
2526
// Use addFormItem instead of add, to wrap fields into form items,
2627
// which displays labels on the side by default
2728
formLayout.addFormItem(revenue, "Revenue");

0 commit comments

Comments
 (0)