@@ -152,7 +152,7 @@ include ../_util-fns
152
152
### Implicit labelling
153
153
154
154
Firstly we will look at the absolute easiest, quickest way to furnish our form controls with accessible labels,
155
- and that is with a pattern called `implicit labelling`.
155
+ and that is with a syntax called `implicit labelling`.
156
156
157
157
`Implicit labelling` is done like this:
158
158
@@ -162,7 +162,7 @@ code-example(language="html" escape="html").
162
162
</label >
163
163
164
164
:marked
165
- Easy hey ? Of course, here the `INPUT` element can be any native `HTML` form element.
165
+ Easy, isn't it ? Of course, here the `INPUT` element can be any native `HTML` form element.
166
166
167
167
Let us now explore how we can use `implicit labelling` to decorate the commonly used native `HTML` form elements
168
168
in our Angular 2 components.
@@ -219,6 +219,12 @@ code-example(language="html" escape="html" format="linenums").
219
219
:marked
220
220
#### Checkboxes
221
221
222
+ .l-sub-section
223
+ :marked
224
+ Because of the many `input` fields making up a `checkbox group`, the usual rule applies for each input but the
225
+ entire group also needs labelled and this is done by using `fieldset` and `legend`.
226
+
227
+ :marked
222
228
Component template:
223
229
224
230
+ makeExample('cb-a11y/ts/app/form-controls/a11y-checkboxes.component.html' )
@@ -267,6 +273,11 @@ code-example(language="html" escape="html" format="linenums").
267
273
:marked
268
274
#### Radiobuttons
269
275
276
+ .l-sub-section
277
+ :marked
278
+ As with the `checkbox group`, a `radiobutton group`, is also labelled using `fieldset` and `legend`.
279
+
280
+ :marked
270
281
Component template:
271
282
272
283
+ makeExample('cb-a11y/ts/app/form-controls/a11y-radiobuttons.component.html' )
@@ -347,20 +358,24 @@ code-example(language="html" escape="html" format="linenums").
347
358
you need to write the input outside the lable for positioning or styling purposes. Or maybe your elements are
348
359
already furnished with id's.
349
360
350
- As alternative you can also use the `explicit labelling` syntax. For this syntax you are required to add an `id` to
351
- the `HTML` form element to connect the label up via a `for / id` pairing [The `for` attribute of the label has to
352
- contain the `id` of the input being labelled].
361
+ As an alternative, you can also use the `explicit labelling` syntax. For this syntax you are required to add an `id` to
362
+ the `HTML` form element. This is then connected up up via a `for / id` pairing * [The `for` attribute of the label has to
363
+ match the `id` of the element being labelled]* .
353
364
354
- This is also the reason why `implicit labelling` could come in very useful with reusable Angular 2 components.
355
- Remember that an `id` should be unique on a page, and any component where `explicit labelling` is used, will need
356
- a way to add unique id's to the elements, unless it is certain that the component will only be used once per page.
365
+ This is also the reason why `implicit labelling` could be more useful with reusable Angular 2 components.
366
+ Remember that an `id` should be unique on a page. This means that any component with `explicit labelling` in its
367
+ template, will need a way ensure that its elements are uniquely labelled, unless it is certain that the component
368
+ will only be used once per page.
357
369
358
- This time we will only look at adding an `explicit label` to an `INPUT`. The examples under the `implicit labelling`
359
- section can then easily be adjusted to use this pattern .
370
+ As an example, we will only look at adding an `explicit label` to an `INPUT`. The examples under the `implicit labelling`
371
+ section can then easily be adjusted to use this syntax .
360
372
361
- **NOTE:** In the example code we are generating `GUID's` for id's to ensure that they are unique. You can use your
362
- own method to do this, as long as every page id is unique.
373
+ .l-sub-section
374
+ :marked
375
+ In the example application code we are generating `GUID's` for id's to ensure that they are unique. You can use your
376
+ own method to do this, as long as every id on a page is unique.
363
377
378
+ :marked
364
379
Component template:
365
380
366
381
+ makeExample('cb-a11y/ts/app/form-controls/a11y-input-explicit.component.html' )
@@ -382,15 +397,15 @@ code-example(language="html" escape="html" format="linenums").
382
397
< input class="form-control"
383
398
id="c90c7f99-330e-4723-bfa8-9ab72a4bd435">
384
399
</div >
385
- </a11y-input-explicit >
400
+ </a11y-input-explicit >
386
401
387
402
:marked
388
403
### Hidden labels
389
404
390
- Sometimes, the design of your page makes more send without a visible label. Think about `search` fields. Do you have
405
+ Sometimes, the design of your page makes more sense without a visible label. Think about `search` fields. Do you have
391
406
to provide a visual label for each one?
392
407
393
- The answer is no. But does that mean we get away with not labelling the field at all?
408
+ The answer is no. But does that mean we get away with not labelling those fields at all?
394
409
395
410
Once again the answer is no.
396
411
@@ -399,12 +414,16 @@ code-example(language="html" escape="html" format="linenums").
399
414
We can either use an `explicitly labelled` input and hide the label with style, or we can use the `aria-label`, which
400
415
is an `ARIA Property`.
401
416
402
- **NOTE:**: We cannot hide the label using the `display` css property. Hidden fields are also hidden to assistive
403
- technologies so we have to use some css magic to either position the label outside of the visible page or
404
- shrinking it right down to be absolutely minute. We wont see it but screen readers will still find it and read it while
405
- still linking it to the correct input via the `for / id' linkup.
417
+ .l-sub-section
418
+ :marked
419
+ We cannot hide the label using the `display` css property. Hidden fields are also hidden to assistive
420
+ technologies so we have to use some css magic to either position the label outside of the visible page or
421
+ shrinking it right down to be absolutely minute. We wont see it but screen readers will still find it and read it while
422
+ still linking it to the correct input via the `for / id` linkup. The following example contains such a
423
+ `visually hidden` style.
406
424
407
- So why don't we create a component showing off both, and use the internal component styles to hide the label.
425
+ :marked
426
+ Let us create a component showing off both, and use the internal component styles to hide the label.
408
427
409
428
+ 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' )
410
429
@@ -420,6 +439,10 @@ code-example(language="html" escape="html" format="linenums").
420
439
code-example( language ="html" escape ="html" format ="linenums" ) .
421
440
<input aria-label =" Filter:" >
422
441
442
+ :marked
443
+ This `aria-label` attribute serves the same purpose as our `LABEL` tags above and will tell screen readers what
444
+ the field is called.
445
+
423
446
.l-main-section
424
447
<a id =" keyboard-shortcuts" ></a >
425
448
:marked
0 commit comments