Commit 425e3d40 authored by Mark Otto's avatar Mark Otto
Browse files

Bring back some 'help text' love for forms with .form-text

- Includes new class
- New docs to support it
- Rearranged older docs
parent 73d98153
17 merge requests!28721Hot test,!27561Adds font-weight-medium to font weight classes,!26437merge,!26197V4 dev xmr,!20778V4 dev,!20539Allow multiple modals,!20493V4 dev display,!20636Fix docs for heading sizes,!22547Finished a new translation for bootstrap,!22143Fix selectable disabled toggle radio buttons,!22598test,!21067dfsa,!25326Adjust examples,!23995Add back cursor: pointer for .btn-link,!23178Spinner,!19141v4: Forms cleanup,!17021v4
Showing with 26 additions and 17 deletions
+26 -17
...@@ -22,7 +22,7 @@ Remember, since Bootstrap utilizes the HTML5 doctype, **all inputs must have a ` ...@@ -22,7 +22,7 @@ Remember, since Bootstrap utilizes the HTML5 doctype, **all inputs must have a `
<div class="form-group"> <div class="form-group">
<label for="exampleInputEmail1">Email address</label> <label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email"> <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
<small id="emailHelp" class="text-muted">We'll never share your email with anyone else.</small> <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="exampleInputPassword1">Password</label> <label for="exampleInputPassword1">Password</label>
...@@ -55,7 +55,7 @@ Remember, since Bootstrap utilizes the HTML5 doctype, **all inputs must have a ` ...@@ -55,7 +55,7 @@ Remember, since Bootstrap utilizes the HTML5 doctype, **all inputs must have a `
<div class="form-group"> <div class="form-group">
<label for="exampleInputFile">File input</label> <label for="exampleInputFile">File input</label>
<input type="file" class="form-control-file" id="exampleInputFile" aria-describedby="fileHelp"> <input type="file" class="form-control-file" id="exampleInputFile" aria-describedby="fileHelp">
<small id="fileHelp" class="text-muted">This is some placeholder block-level help text for the above input. It's a bit lighter and easily wraps to a new line.</small> <small id="fileHelp" class="form-text text-muted">This is some placeholder block-level help text for the above input. It's a bit lighter and easily wraps to a new line.</small>
</div> </div>
<fieldset class="form-group"> <fieldset class="form-group">
<legend>Radio buttons</legend> <legend>Radio buttons</legend>
...@@ -644,7 +644,7 @@ Wrap inputs in grid columns, or any custom parent element, to easily enforce des ...@@ -644,7 +644,7 @@ Wrap inputs in grid columns, or any custom parent element, to easily enforce des
## Help text ## Help text
No official classes exist in Bootstrap 4 for stylizing help text (previously we had `.help-block` in v3), but thanks to utility classes like `.text-muted`, you can create much more flexible help text as needed. Block-level help text in forms can be created using `.form-text` (previously known as `.help-block` in v3). Inline help text can be flexibly implemented using any inline HTML element and utility classes like `.text-muted`.
{% callout warning %} {% callout warning %}
#### Associating help text with form controls #### Associating help text with form controls
...@@ -652,6 +652,20 @@ No official classes exist in Bootstrap 4 for stylizing help text (previously we ...@@ -652,6 +652,20 @@ No official classes exist in Bootstrap 4 for stylizing help text (previously we
Help text should be explicitly associated with the form control it relates to using the `aria-describedby` attribute. This will ensure that assistive technologies – such as screen readers – will announce this help text when the user focuses or enters the control. Help text should be explicitly associated with the form control it relates to using the `aria-describedby` attribute. This will ensure that assistive technologies – such as screen readers – will announce this help text when the user focuses or enters the control.
{% endcallout %} {% endcallout %}
### Block level
Block help text—for below inputs or for longer lines of help text—can be easily achieved with `.form-text`. This class includes `display: block` and adds some top margin for easy spacing from the inputs above.
{% example html %}
<label for="inputPassword5">Password</label>
<input type="password" id="inputPassword5" class="form-control" aria-describedby="passwordHelpBlock">
<p id="passwordHelpBlock" class="form-text text-muted">
Your password must be 8-20 characters long, contain letters and numbers, and must not contain spaces, special characters, or emoji.
</p>
{% endexample %}
### Inline
Inline text can use any typical inline HTML element (be it a `<small>`, `<span>`, or something else). Inline text can use any typical inline HTML element (be it a `<small>`, `<span>`, or something else).
{% example html %} {% example html %}
...@@ -666,16 +680,6 @@ Inline text can use any typical inline HTML element (be it a `<small>`, `<span>` ...@@ -666,16 +680,6 @@ Inline text can use any typical inline HTML element (be it a `<small>`, `<span>`
</form> </form>
{% endexample %} {% endexample %}
Block help text—for below inputs or for longer lines of help text—can be easily achieved with a `<p>`.
{% example html %}
<label for="inputPassword5">Password</label>
<input type="password" id="inputPassword5" class="form-control" aria-describedby="passwordHelpBlock">
<p id="passwordHelpBlock" class="text-muted">
Your password must be 8-20 characters long, contain letters and numbers, and must not contain spaces, special characters or emoji.
</p>
{% endexample %}
## Validation ## Validation
Bootstrap includes validation styles for danger, warning, and success states on form controls. Here's a rundown of how they work: Bootstrap includes validation styles for danger, warning, and success states on form controls. Here's a rundown of how they work:
...@@ -709,19 +713,19 @@ Ensure that an alternative indication of state is also provided. For instance, y ...@@ -709,19 +713,19 @@ Ensure that an alternative indication of state is also provided. For instance, y
<label class="col-form-label" for="inputSuccess1">Input with success</label> <label class="col-form-label" for="inputSuccess1">Input with success</label>
<input type="text" class="form-control form-control-success" id="inputSuccess1"> <input type="text" class="form-control form-control-success" id="inputSuccess1">
<div class="form-control-feedback">Success! You've done it.</div> <div class="form-control-feedback">Success! You've done it.</div>
<small class="text-muted">Example help text that remains unchanged.</small> <small class="form-text text-muted">Example help text that remains unchanged.</small>
</div> </div>
<div class="form-group has-warning"> <div class="form-group has-warning">
<label class="col-form-label" for="inputWarning1">Input with warning</label> <label class="col-form-label" for="inputWarning1">Input with warning</label>
<input type="text" class="form-control form-control-warning" id="inputWarning1"> <input type="text" class="form-control form-control-warning" id="inputWarning1">
<div class="form-control-feedback">Shucks, check the formatting of that and try again.</div> <div class="form-control-feedback">Shucks, check the formatting of that and try again.</div>
<small class="text-muted">Example help text that remains unchanged.</small> <small class="form-text text-muted">Example help text that remains unchanged.</small>
</div> </div>
<div class="form-group has-danger"> <div class="form-group has-danger">
<label class="col-form-label" for="inputDanger1">Input with danger</label> <label class="col-form-label" for="inputDanger1">Input with danger</label>
<input type="text" class="form-control form-control-danger" id="inputDanger1"> <input type="text" class="form-control form-control-danger" id="inputDanger1">
<div class="form-control-feedback">Shit, that username's taken. Try another?</div> <div class="form-control-feedback">Shit, that username's taken. Try another?</div>
<small class="text-muted">Example help text that remains unchanged.</small> <small class="form-text text-muted">Example help text that remains unchanged.</small>
</div> </div>
{% endexample %} {% endexample %}
......
...@@ -181,6 +181,11 @@ select.form-control-lg { ...@@ -181,6 +181,11 @@ select.form-control-lg {
margin-bottom: $form-group-margin-bottom; margin-bottom: $form-group-margin-bottom;
} }
.form-text {
display: block;
margin-top: ($spacer * .25);
}
// Checkboxes and radios // Checkboxes and radios
// //
...@@ -244,7 +249,7 @@ select.form-control-lg { ...@@ -244,7 +249,7 @@ select.form-control-lg {
// Apply contextual and semantic states to individual form controls. // Apply contextual and semantic states to individual form controls.
.form-control-feedback { .form-control-feedback {
margin-top: .5rem; margin-top: ($spacer * .25);
} }
.form-control-success, .form-control-success,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment