@@ -174,9 +174,14 @@ code-example(language="html" escape="html").
174
174
:marked
175
175
#### Inputs and textareas
176
176
177
- + makeTabs('cb-a11y/ts/app/form-controls/a11y-form-controls.component.html, cb-a11y/ts/app/form-controls/a11y-form-controls.component.html' ,
178
- 'cb-a11y-form-controls-input-implicit,cb-a11y-form-controls-textarea-implicit' ,
179
- 'Implicitly labelled input,Implicitly labelled textarea' )
177
+ Labelling an input:
178
+
179
+ + makeExample('cb-a11y/ts/app/form-controls/a11y-form-controls.component.html' ,'cb-a11y-form-controls-input-implicit' )
180
+
181
+ :marked
182
+ Labelling a textarea:
183
+
184
+ + makeExample('cb-a11y/ts/app/form-controls/a11y-form-controls.component.html' ,'cb-a11y-form-controls-textarea-implicit' )
180
185
181
186
:marked
182
187
#### Checkboxes and radiobuttons
@@ -186,10 +191,16 @@ code-example(language="html" escape="html").
186
191
Because of the many `input` fields making up a `checkbox group` or `radiobutton group`, the usual rule applies
187
192
for each input but the entire group also needs labelled and this is done by using `fieldset` and `legend`.
188
193
189
- + makeTabs('cb-a11y/ts/app/form-controls/a11y-form-controls.component.html, cb-a11y/ts/app/form-controls/a11y-form-controls.component.html' ,
190
- 'cb-a11y-form-controls-checkboxes-implicit,cb-a11y-form-controls-radiobuttons-implicit' ,
191
- 'Implicitly labelled Checkboxes,Implicitly labelled Radiobuttons' )
194
+ :marked
195
+ Labelling checkboxes:
196
+
197
+ + makeExample('cb-a11y/ts/app/form-controls/a11y-form-controls.component.html' ,'cb-a11y-form-controls-checkboxes-implicit' )
192
198
199
+ :marked
200
+ Labelling radiobuttons:
201
+
202
+ + makeExample('cb-a11y/ts/app/form-controls/a11y-form-controls.component.html' ,'cb-a11y-form-controls-radiobuttons-implicit' )
203
+
193
204
:marked
194
205
#### Select lists
195
206
@@ -206,42 +217,13 @@ code-example(language="html" escape="html").
206
217
the `HTML` form element. This is then connected up up via a `for / id` pairing *[The `for` attribute of the label has to
207
218
match the `id` of the element being labelled]* .
208
219
209
- This is also the reason why `implicit labelling` could be more useful with reusable Angular 2 components.
210
- Remember that an `id` should be unique on a page. This means that any component with `explicit labelling` in its
211
- template, will need a way ensure that its elements are uniquely labelled, unless it is certain that the component
212
- will only be used once per page.
220
+ Remember, this is why we said that `implicit labelling` is recommended due to the extra code you may required to keep
221
+ the id's unique per page.
213
222
214
- As an example, we will only look at adding an `explicit label` to an ` input`. The examples under the `implicit labelling`
223
+ As an example, we will only look at adding an `explicit label` to a `text input`. The examples under the `implicit labelling`
215
224
section can then easily be adjusted to use this syntax.
216
225
217
- .l-sub-section
218
- :marked
219
- In the example application code we are generating `GUID's` for id's to ensure that they are unique. You can use your
220
- own method to do this, as long as every id on a page is unique.
221
-
222
- :marked
223
- Component template:
224
-
225
- + makeExample('cb-a11y/ts/app/form-controls/a11y-input-explicit.component.html' )
226
-
227
- :marked
228
- User writes:
229
-
230
- + makeExample('cb-a11y/ts/app/form-controls/a11y-form-controls.component.html' ,'cb-a11y-form-controls-input-explicit-usage' )
231
-
232
- :marked
233
- Rendered out:
234
-
235
- code-example( language ="html" escape ="html" format ="linenums" ) .
236
- <a11y-input-explicit >
237
- <div class =" form-group" >
238
- <label for =" c90c7f99-330e-4723-bfa8-9ab72a4bd435" >
239
- Label for input:
240
- </label >
241
- < input class="form-control"
242
- id="c90c7f99-330e-4723-bfa8-9ab72a4bd435">
243
- </div >
244
- </a11y-input-explicit >
226
+ + makeExample('cb-a11y/ts/app/form-controls/a11y-form-controls.component.html' , 'cb-a11y-form-controls-input-explicit' )
245
227
246
228
:marked
247
229
### Hidden labels
@@ -265,27 +247,32 @@ code-example(language="html" escape="html" format="linenums").
265
247
shrinking it right down to be absolutely minute. We wont see it but screen readers will still find it and read it while
266
248
still linking it to the correct input via the `for / id` linkup. The following example contains such a
267
249
`visually hidden` style.
268
-
250
+
269
251
:marked
270
- Let us create a component showing off both, and use the internal component styles to hide the label.
271
-
272
- + makeTabs ('cb-a11y/ts/app/form-controls/ a11y-hidden-labels.component.html, cb-a11y/ts/app/form-controls/a11y-hidden-labels.component.ts, cb-a11y/ts/app/ form-controls/a11y-hidden-labels.component.css' , null , 'a11y- hidden-labels.component.html,a11y-hidden-labels.component.ts,a11y-hidden-labels.component.css ' )
273
-
252
+ Example of a good visually hidden css style:
253
+
254
+ + makeExample ('cb-a11y/ts/a11y.css' , ' cb-a11y- form-controls-visually- hidden-style ' )
255
+
274
256
:marked
275
- Which can then be used as :
257
+ Applying the style to a control to hide the label :
276
258
277
- + makeExample('cb-a11y/ts/app/form-controls/a11y-form-controls.component.html' ,'cb-a11y-form-controls-hidden-labels-usage ' )
259
+ + makeExample('cb-a11y/ts/app/form-controls/a11y-form-controls.component.html' , 'cb-a11y-form-controls-hidden-label-explicit ' )
278
260
279
261
:marked
280
- The way the label is rendered int he final `HTML` is no secret to us anymore, but when you inspect the second input,
281
- you will see that an `aria-label` attribute has been added to the input. Simplified:
262
+ Alternatively labelling a control with `aria-label`:
282
263
283
- code-example( language ="html" escape ="html" format ="linenums" ) .
284
- <input aria-label =" Filter:" >
264
+ + makeExample('cb-a11y/ts/app/form-controls/a11y-form-controls.component.html' ,'cb-a11y-form-controls-hidden-label-aria' )
285
265
286
266
:marked
287
- This `aria-label` attribute serves the same purpose as our `LABEL ` tags above and will tell screen readers what
267
+ This `aria-label` attribute serves the same `a11y` purpose as our `label ` tags above and will tell screen readers what
288
268
the field is called.
269
+
270
+ .l-sub-section
271
+ :marked
272
+ So why not simply always use `aria-label`? This is because adding the `label` element not only provides the visual
273
+ label, but linking a `label` to a `form control` also means that clicking on the `label` will select the
274
+ `form control` itself. This touches on another area of `a11y`, as this also assists users with motor disabilites
275
+ to more easily select them.
289
276
290
277
:marked
291
278
### Labelling custom form controls
@@ -324,6 +311,11 @@ code-example(language="html" escape="html" format="linenums").
324
311
</div >
325
312
</a11y-custom-control >
326
313
314
+ .l-sub-section
315
+ :marked
316
+ In the example application code we are generating `GUID's` for id's to ensure that they are unique. You can use your
317
+ own method to do this, as long as every id on a page is unique.
318
+
327
319
328
320
.l-main-section
329
321
<a id =" keyboard-shortcuts" ></a >
0 commit comments