Skip to content

Commit b66055e

Browse files
authored
Add ARIA tags for input validation message examples (#798)
1 parent aab413f commit b66055e

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

docs/product/components/inputs.html

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,12 @@
102102
<p class="stacks-copy">
103103
In most cases, validation states shouldn’t be shown until after the user has submitted the form. There are certain exceptions where it can be appropriate to show a validation state without form submission—after a sufficient delay. For example, validating the existence of a username can occur after the user has stopped typing, or when they’ve deselected the input.
104104
</p>
105-
<p class="stacks-copy mb32">
105+
<p class="stacks-copy">
106106
Once the user is presented validation states, they can be cleared as soon as the user interacts with the form field. For example, the error state for an incorrect password should be cleared as soon as the user focuses the input to re-enter their password.
107107
</p>
108+
<p class="stacks-copy mb32">
109+
Similarly to using <code class="stacks-code">for</code> with labels, validation messages below inputs should be associated with their respective fields using the <code class="stacks-code">aria-describedby</code> attribute for accessible behavior.
110+
</p>
108111

109112
{% header "h3", "Validation examples" %}
110113
{% header "h4", "Warning" %}
@@ -113,47 +116,51 @@
113116
<div class="d-flex gs4 gsy fd-column has-warning">
114117
<label class="flex--item s-label" for="example-warning">Username</label>
115118
<div class="d-flex ps-relative">
116-
<input class="s-input" id="example-warning" type="text" placeholder="" />
119+
<input class="s-input" id="example-warning" type="text" placeholder="" aria-describedby="example-warning-desc" />
117120
@Svg.Alert.With("s-input-icon")
118121
</div>
119-
<p class="flex--item s-input-message">Caps lock is on! <a>Having trouble entering your username?</a></p>
122+
<p id="example-warning-desc" class="flex--item s-input-message">Caps lock is on! <a>Having trouble entering your username?</a></p>
120123
</div>
121124
{% endhighlight %}
122125
<div class="stacks-preview--example">
123126
<div class="flex--item">
124127
<div class="d-flex gs4 gsy fd-column has-warning">
125128
<label class="flex--item s-label" for="example-warning">Username</label>
126129
<div class="d-flex ps-relative">
127-
<input class="s-input" id="example-warning" type="text" value="AA" />
130+
<input class="s-input" id="example-warning" type="text" value="AA" aria-describedby="example-warning-desc" />
128131
{% icon "Alert", "s-input-icon" %}
129132
</div>
130-
<p class="flex--item s-input-message">Caps lock is on! <a>Having trouble entering your username?</a></p>
133+
<p id="example-warning-desc" class="flex--item s-input-message">Caps lock is on! <a>Having trouble entering your username?</a></p>
131134
</div>
132135
</div>
133136
</div>
134137
</div>
135138

136139
{% header "h4", "Error" %}
140+
{% tip, "warning", "mb24" %}
141+
<p class="mb0">In addition to using the "error" state for a field, be sure to use the <a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-invalid_attributev"><code class="stacks-code">aria-invalid</code></a> attribute to indicate to assistive technology that respective fields have failed validation.</p>
142+
{% endtip %}
143+
137144
<div class="stacks-preview">
138145
{% highlight html %}
139146
<div class="d-flex gs4 gsy fd-column has-error">
140-
<label class="flex--item s-label" for="example-warning">Username</label>
147+
<label class="flex--item s-label" for="example-error">Username</label>
141148
<div class="d-flex ps-relative">
142-
<input class="s-input" id="example-warning" type="text" placeholder="e.g. johndoe111" />
149+
<input class="s-input" id="example-error" type="text" placeholder="e.g. johndoe111" aria-describedby="example-error-desc" aria-invalid="true" />
143150
@Svg.AlertCircle.With("s-input-icon")
144151
</div>
145-
<p class="flex--item s-input-message">You must provide a username. <a>Forgot your username?</a></p>
152+
<p id="example-error-desc" class="flex--item s-input-message">You must provide a username. <a>Forgot your username?</a></p>
146153
</div>
147154
{% endhighlight %}
148155
<div class="stacks-preview--example">
149156
<div class="flex--item">
150157
<div class="d-flex gs4 gsy fd-column has-error">
151158
<label class="flex--item s-label" for="example-error">Username</label>
152159
<div class="d-flex ps-relative">
153-
<input class="s-input" id="example-error" type="text" />
160+
<input class="s-input" id="example-error" type="text" aria-describedby="example-error-desc" />
154161
{% icon "AlertCircle", "s-input-icon" %}
155162
</div>
156-
<p class="flex--item s-input-message">You must provide a username. <a>Forgot your username?</a></p>
163+
<p id="example-error-desc" class="flex--item s-input-message">You must provide a username. <a>Forgot your username?</a></p>
157164
</div>
158165
</div>
159166
</div>
@@ -163,23 +170,23 @@
163170
<div class="stacks-preview">
164171
{% highlight html %}
165172
<div class="d-flex gs4 gsy fd-column has-success">
166-
<label class="flex--item s-label" for="example-warning">Username</label>
173+
<label class="flex--item s-label" for="example-success">Username</label>
167174
<div class="d-flex ps-relative">
168-
<input class="s-input" id="example-warning" type="text" />
175+
<input class="s-input" id="example-success" type="text" aria-describedby="example-success-desc" />
169176
@Svg.Checkmark.With("s-input-icon")
170177
</div>
171-
<p class="flex--item s-input-message">That name is available! <a>Why do we require a username?</a></p>
178+
<p id="example-success-desc" class="flex--item s-input-message">That name is available! <a>Why do we require a username?</a></p>
172179
</div>
173180
{% endhighlight %}
174181
<div class="stacks-preview--example">
175182
<div class="flex--item">
176183
<div class="d-flex gs4 gsy fd-column has-success">
177184
<label class="flex--item s-label" for="example-success">Username</label>
178185
<div class="d-flex ps-relative">
179-
<input class="s-input" id="example-success" type="text" value="aaronshekey" />
186+
<input class="s-input" id="example-success" type="text" value="aaronshekey" aria-describedby="example-success-desc" />
180187
{% icon "Checkmark", "s-input-icon" %}
181188
</div>
182-
<p class="flex--item s-input-message">That name is available! <a>Why do we require a username?</a></p>
189+
<p id="example-success-desc" class="flex--item s-input-message">That name is available! <a>Why do we require a username?</a></p>
183190
</div>
184191
</div>
185192
</div>

0 commit comments

Comments
 (0)