Merge pull request #18654 from patrickhlauke/docs-helptext1

Docs: reintroduce `aria-describedby` advice for help text
This commit is contained in:
Patrick H. Lauke 2015-12-24 13:38:46 +00:00
commit e2bf1e9fae

View File

@ -21,8 +21,8 @@ Remember, since Bootstrap utilizes the HTML5 doctype, **all inputs must have a `
<form> <form>
<fieldset class="form-group"> <fieldset class="form-group">
<label for="exampleInputEmail1">Email address</label> <label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email"> <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
<small class="text-muted">We'll never share your email with anyone else.</small> <small id="emailHelp" class="text-muted">We'll never share your email with anyone else.</small>
</fieldset> </fieldset>
<fieldset class="form-group"> <fieldset class="form-group">
<label for="exampleInputPassword1">Password</label> <label for="exampleInputPassword1">Password</label>
@ -54,8 +54,8 @@ Remember, since Bootstrap utilizes the HTML5 doctype, **all inputs must have a `
</fieldset> </fieldset>
<fieldset class="form-group"> <fieldset class="form-group">
<label for="exampleInputFile">File input</label> <label for="exampleInputFile">File input</label>
<input type="file" class="form-control-file" id="exampleInputFile"> <input type="file" class="form-control-file" id="exampleInputFile" aria-describedby="fileHelp">
<small 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="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>
</fieldset> </fieldset>
<div class="radio"> <div class="radio">
<label> <label>
@ -517,19 +517,33 @@ Wrap inputs in grid columns, or any custom parent element, to easily enforce des
No official help text classes exist in Bootstrap 4 (previously we had `.help-block` in v3), but thanks to our utility classes like `.text-muted`, you can create much more flexible help text as you need it. No official help text classes exist in Bootstrap 4 (previously we had `.help-block` in v3), but thanks to our utility classes like `.text-muted`, you can create much more flexible help text as you need it.
{% callout warning %}
#### Associating help text with form controls
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 %}
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 %}
<small class="text-muted"> <form class="form-inline">
Some inline text with a small tag looks like this. <div class="form-group">
</small> <label for="inputPassword4">Password</label>
<input type="password" id="inputPassword4" class="form-control" aria-describedby="passwordHelpInline">
<small id="passwordHelpInline" class="text-muted">
Must be 8-20 characters long.
</small>
</div>
</form>
{% endexample %} {% endexample %}
Block help text—for below inputs or for longer lines of help text—can be easily achieved with a `<p>`. Block help text—for below inputs or for longer lines of help text—can be easily achieved with a `<p>`.
{% example html %} {% example html %}
<p class="text-muted"> <label for="inputPassword5">Password</label>
A block of help text that breaks onto a new line and may extend beyond one line. <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> </p>
{% endexample %} {% endexample %}