You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(form-legend): Add styling for compound form with a tooltip icon next to the legend (#3151)
* fix(form-legend): Add example in compound form for a tooltip icon next to the legend
* fix(form-legend): export compoundForm for future use
* fix(form-legend): Add tests
* fix(form-legend): Attach styling to new class instead of utility
* fix(form-legend-icon): Remove example
* fix(form-legend-icon): Update docs to include form layout info and legend icon blockquote
* fix(form-legend-icon): remove form-layout from the components list
* fix(form-legend-icon): Add inline help as example in input
* fix(form-legend-icon): Remove inline class
* fix(form-legend): Skip test for now
* Update tests
An HTML form element contains a HTML label and element
14
16
</div>
15
17
18
+
There are many types of form elements, including [inputs](/input), [text areas](/textarea), [checkboxes](/checkbox), and [radio buttons](/radio-group). Visit the individual component pages for in-depth details of specific states and visuals.
19
+
16
20
## Structuring a form element
17
21
18
22
To create a form element, a `<div>` element with the class `slds-form-element` is required.
@@ -32,7 +36,7 @@ A form element is made up of three primary elements, the label (`slds-form-eleme
32
36
A form label should use the `<label>` element with the class `slds-form-element__label`.
It is required to have the <codeclassName="doc">for</code> attr applied the the label that points to the ID of the form element, <codeclassName="doc"><inputid="unique-id"></code>.
39
+
Labels must have the <codeclassName="doc">for</code> attribute applied, and its value must match the ID of the associated form element, like <codeclassName="doc"><inputid="unique-id-of-input"></code>. This association ensures that assistive technology informs users about what information to enter where.
36
40
</Blockquote>
37
41
38
42
<CodeBlocktoggleCode={false}>
@@ -110,11 +114,13 @@ By default, the overall form element takes up 54px of vertical space. If you req
110
114
111
115
### Feedback
112
116
113
-
A form element provides two types of feedback, a required form element and a form element with an error.
117
+
A form element can have various methods of feedback, such as a required denotation or an inline error message.
114
118
115
119
#### Required
116
120
117
-
When a form element is required, an `<abbr>` should be injected before the `<input>` with the class `slds-required`.
121
+
When a form element is required, an `<abbr>` should be injected before the `<input>` and within the `<label>` and have the class `slds-required`.
122
+
123
+
The `<input>` element should also have the HTML attribute required or required="". Similarily, if it is disabled, it should have the disabled or disabled="" attribute. Do not use true/false values inside the required or disabled because the mere presence of these attributes signifies the field is required or disabled.
118
124
119
125
<Exampletitle="Form Element - Required">
120
126
@@ -128,10 +134,10 @@ When a form element is required, an `<abbr>` should be injected before the `<inp
128
134
129
135
#### Error
130
136
131
-
If an error has occured while submitting a form, the form element with an error should provide feedback.
137
+
If an error has occured while submitting a form, the form element with an error should provide feedback. The `slds-has-error` class is placed on the `<div class="slds-form-element">`. Then, the error message for the user is placed in a `<span>` with the `slds-form-element__help` class.
When a form element displayed feedback notifying the user of an error, the error string should be linked to the element by adding <codeclassName="doc">aria-describedby</code> attribute to the <codeclassName="doc"><input></code> and point to the error message ID.
140
+
When a form element displays feedback notifying the user of an error, the error string should be linked to the element by adding the <codeclassName="doc">aria-describedby</code> attribute to the <codeclassName="doc"><input></code>. The `aria-describedby` attribute must reference the id of the error message. This configuration allows screen readers to read the associated error message when the invalid field is focused.
135
141
</Blockquote>
136
142
137
143
<Exampletitle="Form Element - Error">
@@ -140,17 +146,53 @@ If an error has occured while submitting a form, the form element with an error
Layout helper classes are available through the following class names: `slds-form_stacked` and `slds-form_horizontal`. For optimal spacing and layout, ensure the `slds-form-element` class is present on each element within the form.
163
+
164
+
### Stacked
165
+
166
+
To vertically stack `<label>` and `<input>` pairs, place `slds-form--stacked` on the wrapper of the form for optimal spacing.
167
+
168
+
<Exampletitle="Form Layout - Stacked">
169
+
<CodeView>
170
+
<Form/>
171
+
</CodeView>
172
+
</Example>
173
+
174
+
### Horizontal
175
+
176
+
To horizontally align a `<label>` and `<input>`, use the `slds-form--horizontal` class on the wrapper around the form. A `slds-form-element__label` takes up 33% of the width, and the `slds-form-element__control` uses the remaining 66%.
To use field level help with a `<legend>` (as opposed to a `<label>`), the `<legend>` and the `<div>` with the help icon must be siblings. Additionally, you'll need to add the class `slds-form-element__legend_has-tooltip` to the `<legend>`. Only add this class when your `<legend>` has adjacent field level help, otherwise you'll experience unexpected layouts.
Copy file name to clipboardExpand all lines: ui/components/form-layout/__tests__/__snapshots__/Form_Layout_renders_a_base_form_layout_horizontally.json
Copy file name to clipboardExpand all lines: ui/components/form-layout/__tests__/__snapshots__/Form_Layout_renders_a_compound_form_layout_with_a_tooltip.json
// Copyright (c) 2015-present, salesforce.com, inc. All rights reserved
2
2
// Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license
3
-
4
-
/**
5
-
* To vertically stack `<label>` and `<input>` pairs, place `.slds-form--stacked` on the wrapper of the form for optimal spacing.
6
-
*
7
-
* To horizontally align a `<label>` and `<input>`, use the `.slds-form--horizontal` class on the wrapper around the form. A `.slds-form-element__label` takes up 33% of the width, and the `.slds-form-element__control` uses the remaining 66%.
8
-
*
9
-
* For optimum spacing and layout, wrap each element in `.slds-form-element`. Layout helper classes are available through the following class names, `.slds-form--stacked`, `.slds-form--horizontal` and `.slds-form--inline`.
10
-
*
11
-
* The read-only state is for form elements that can’t be modified. It is used for small, non-editable form fields that sit next to inputs and allows the size and height to align. It is not meant for large paragraphs of text.
12
-
*
13
-
* Because the read-only field state has no `<input>`, don’t use a `<label>` to provide better accessibility for screen readers and keyboard navigators. Instead, use a `<span>` with the `.slds-form-element__label` class. Instead of an `<input>`, use the `.slds-form-element__static` class inside the `.slds-form-element__control` wrapper.
14
-
*
15
-
* Error states alert the user when content in the form is invalid. The `.slds-has-error` class is placed on the `<div class="slds-form-element">`. Place the error message for the user in a `<span>` with the `.slds-form-element__help` class.
16
-
*
17
-
* The native form elements, `<input>`, `<textarea>`, `<select>`, `<input type='checkbox'>`, and `<input type='radio'>`, receive validation styling for `disabled`, `checked`, and `checked disabled`, if applicable.
18
-
*
19
-
* #### Accessibility
20
-
*
21
-
* Every field requires an associated, non-empty `<label>` element. The label should have a `for` attribute that references the `id` of the field. For example, `<label for="emailAddress">Enter email address:</label>` and `<input id="emailAddress">`. This association ensures that assistive technology informs users what information to enter where.
22
-
*
23
-
* If the field is required, the `<input>` element should have the HTML attribute `required` or `required=""`. Similarily, if it is disabled, it should have the `disabled` or `disabled=""` attribute. Do not use true/false values inside the `required` or `disabled` because the mere presence of these attributes signifies the field is required or disabled.
24
-
*
25
-
* If the field is invalid and displays an error message, the `<input>` element should have an `aria-describedby` attribute that references the `id` of the error message. This configuration allows screen readers to read the associated error message when the invalid field is focused.
26
-
*
27
-
* @summary An HTML form contains interactive controls to submit information to a web server.
0 commit comments