Skip to content

Commit c6948e1

Browse files
authored
Merge pull request #317 from dxc-technology/Layout-pattern-Form
Layout pattern form documentation draft
2 parents 5e669cc + a6d17eb commit c6948e1

File tree

4 files changed

+195
-0
lines changed

4 files changed

+195
-0
lines changed

guidelines/patterns/Form/README.md

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
2+
# Forms
3+
4+
A form is a group of related input controls. Forms can be presented as dedicated pages or dialogs depending on the use case.
5+
6+
* [Structure](#structure)
7+
* [Variants](#variants)
8+
* [Anatomy](#anatomy)
9+
* [Alignment](#alignment)
10+
* [Form validation](#form-validation)
11+
* [Required vs optional](#required-vs-optional)
12+
* [Progressive disclosure](#progressive-disclosure)
13+
* [Helping users](#helping-users)
14+
* [Layout](#layout)
15+
* [Accessibility](#accessibility)
16+
17+
18+
## Structure
19+
20+
21+
Form elements should move in a single direction so they should only be distributed through:
22+
23+
* One column when the progression of the form is vertical
24+
* One row when the progression is horizontal.
25+
26+
Horizontally stacking input fields in a vertically moving form is only acceptable when they’re related, for example, name and surname.
27+
28+
## Variants
29+
30+
Depending on the use case, Forms may be presented as dedicated pages or dialogs.
31+
32+
![Form pattern variants](images/form_variants.png)
33+
34+
_Form pattern variants_
35+
36+
### Page form
37+
38+
For more complex, lengthier or multistep requests for user input.
39+
40+
41+
| Type | Description | Linked to |
42+
| :--- | :--- | :--- |
43+
| Regular | Full page form | |
44+
| Accordion Forms | To group similar content and hide or show it depending on user needs or preferences | [Accordion](components/accordion/README.md) |
45+
| Multistep Forms | Provides a linear and mandatory step progression through a defined process | [Wizard](components/wizard/README.md)|
46+
47+
### Dialog form
48+
49+
For critical, infrequent requests for user input often related to editing and management tasks.
50+
51+
* Use a dialog form when dealing with less than five inputs.
52+
* Do not hide information in accordions or tabs.
53+
54+
## Anatomy
55+
56+
![Example of the form anatomy](images/form_anatomy.png)
57+
58+
_Example of the form anatomy_
59+
60+
1. **Text inputs**: Enable users to input free-form text.
61+
2. **Data inputs**: Information can be entered through a variety of non-free form input fields (checkboxes, radio buttons, dropdowns and selects, file uploader, date pickers, toggles, etc.)
62+
3. **Buttons**: Allows users to submit or exit a form.
63+
64+
65+
### Text inputs
66+
67+
These controls enable users to provide input on forms by selecting from a set of pre-determined options or a limited range of values. Carbon provides a variety of data input components that enable a user to make a selection. Each component was created to serve a specific use case.
68+
69+
| Type | Description |
70+
| :--- | :--- |
71+
| [Input-text](components/text-input/README.md) | To capture several words maximum |
72+
| [Text-area](components/text-input/README.md) | To capture multiple lines of text |
73+
74+
### Data inputs
75+
76+
These controls enable users to provide input on forms by selecting from a set of pre-determined options or a limited range of values. Consider how many options you need to present as well as how many items the user may need to select.
77+
78+
| Type | Description |
79+
| :--- | :--- |
80+
| [Radio button](components/radio/README.md) | To select only one option from two or more choices |
81+
| [Checkbox](components/checkbox/README.md) | To select or deselect one or more choices |
82+
| [Toogle group](components/toggle/README.md) | To choose one of two binary options or select multiple options |
83+
| [Date picker](components/date/README.md) | To input/select a date from a calendar |
84+
| [Slider](components/slider/README.md) | To select one number from a numerical range |
85+
| [Switch](components/switch/README.md) | To activate or deactivate an option |
86+
| [Upload](components/upload/README.md)| To upload/attach a file or multiple files to a form |
87+
88+
### Buttons
89+
90+
Use a primary button for the main action, a secondary button for secondary actions like Cancel or Discard.
91+
92+
| Type | Description |
93+
| :--- | :--- |
94+
| [Button](components/text-input/README.md) | Initialize an action or function when the user interacts with them |
95+
96+
## Alignment
97+
98+
| Type | Description |
99+
| :--- | :--- |
100+
| Left-aligned | Non-dialog, in-page forms |
101+
| Right-aligned | Multistep forms/wizards when the primary action implies a navigation step forward |
102+
| Center-aligned | All forms that are presented in dialogs |
103+
104+
## Form validation
105+
106+
Validation should be shown inline and can happen in real-time or on form submission. Real-time validation should confirm correct content or assist a user to input the correct information to prevent them from attempting to submit the form with possibly incorrect information. The validation should appear when the user has clicked away from the text field and always be visible and not placed in a tooltip.
107+
108+
When present, the validation message is placed directly below the input replacing the [helper text](#helping-users) until the error is fixed.
109+
110+
### Errors
111+
112+
An error indicates content that can’t be submitted or was found to be invalid after submission and needs to be corrected.
113+
114+
![Handling errors in forms](images/form_error_handling.png)
115+
116+
_**Left**: `text-input` error message prompting the user there is an icorrect value._
117+
118+
_**Right**: Alert component showing an error after submitting._
119+
120+
#### User errors to handle
121+
122+
* Incorrectly formatting data
123+
* Leaving a mandatory field blank
124+
* Leaving a mandatory field incomplete
125+
126+
## Required vs optional
127+
128+
All fields in a form are assumed required, with optional fields being tagged as so in the label. An excess of optional fields should be avoided.
129+
130+
## Progressive disclosure
131+
132+
The user goal when interacting with a form should be taken into account when deciding whether a field needs to be disabled or hidden from the interface.
133+
134+
**Disabled fields**
135+
136+
Disable a field if a user does not have access grants for an item, but still needs disclosure to it.
137+
138+
* The field is still displayed in the form, but cannot be edited. If it can become editable to the user (depending on certain conditions, like pressing a button or completing another field), it should stay disabled until then.
139+
* Disabled fields give extra thought for the user about why it is not available.
140+
* The visual distinction between disabled/enabled fields should be very explicit and clear. Be sure to always include a help text below the field, explaining why it’s disabled.
141+
142+
**Hidden fields**
143+
144+
Hide a field if a user doesn’t need disclosure or access to an item.
145+
146+
* This option is relevant specifically for system security measures when some information should not be available in the user interface.
147+
* Hiding fields allows for progressive disclosure.
148+
149+
For example, as the user enters data in a form or makes a selection, more fields may be displayed or hidden, but the user only has to focus on the necessary fields to complete a task.
150+
151+
## Helping users
152+
153+
Helper text can be used as additional instructions to the user when filling in the form. It should be visible even on focus state and it can be replaced by an error message until the error is fixed in order to prevent adding more lines of text. More information can be found in the [helper text section](components/text-input/README.md) of the `text-input` component.
154+
155+
## Layout
156+
157+
### Form headings
158+
159+
| Token | Description |
160+
| :--- | :--- |
161+
| `headings-h3` | Form title |
162+
| `headings-h4` | Form section title |
163+
| `headings-h5` | Form sub-section title |
164+
165+
### Spacing
166+
167+
Every part of a UI should be intentional including the empty space between elements. The amount of space between items creates relationships and hierarchy. In Halstack we create hierarchy through our spacing scale. Use the component scale to create hierarchy between text inputs, data inputs, sections and form buttons.
168+
169+
| Element | Description | Full page | Modal |
170+
| :--- | :--- | :--- | :--- |
171+
| Individual inputs | Spacing between inputs | 32px / `spacing-07` | 24px / `spacing-06` |
172+
| Sections | Spacing between sections | 40px / `spacing-08` | 32px / `spacing-07` |
173+
| Buttons | Spacing between last form element and buttons | 48px / `spacing-09` | 48px / `spacing-09` |
174+
175+
## Accessibility
176+
177+
### WCAG 2.2
178+
179+
* Understanding WCAG 2.2 - [SC 3.2.2: On Input](https://www.w3.org/WAI/WCAG22/Understanding/on-input.html)
180+
* Understanding WCAG 2.2 - [SC 1.3.1: Info and relationships](https://www.w3.org/WAI/WCAG22/Understanding/info-and-relationships.html)
181+
* Understanding WCAG 2.2 - [SC 1.3.5: Identify input purpose](https://www.w3.org/WAI/WCAG22/Understanding/identify-input-purpose.html)
182+
* Understanding WCAG 2.2 - [SC 3.3.1: Error identification](https://www.w3.org/WAI/WCAG22/Understanding/error-identification.html)
183+
* Understanding WCAG 2.2 - [SC 1.4.1: Use of color](https://www.w3.org/WAI/WCAG22/Understanding/use-of-color.html)
184+
185+
### Related content
186+
187+
* [W3C Guidance for creating forms that meet WCAG](https://www.w3.org/WAI/tutorials/forms/instructions/)
188+
189+
190+
_________________________
191+
192+
[Edit this page on GitHub](https://github.com/dxc-technology/halstack-style-guide/blob/master/guidelines/patterns/form/README.md)
193+
194+
195+
66.5 KB
Loading
24.4 KB
Loading
20.4 KB
Loading

0 commit comments

Comments
 (0)