Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit debc73d

Browse files
committed
docs(cb-a11y): Content - Form controls
1 parent 61df40f commit debc73d

File tree

5 files changed

+47
-3
lines changed

5 files changed

+47
-3
lines changed

public/docs/_examples/cb-a11y/ts/app/form-controls/a11y-form-controls.component.html

+2
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ <h3>Hiding labels</h3>
5050
<hr>
5151
</header>
5252

53+
<!-- #docregion cb-a11y-form-controls-hidden-labels-usage -->
5354
<a11y-hidden-labels [label1]="'Search:'"
5455
[label2]="'Filter:'">
5556
</a11y-hidden-labels>
57+
<!--#enddocregion-->
5658

5759
</section>
5860
<section class="row well">

public/docs/_examples/cb-a11y/ts/app/form-controls/a11y-hidden-labels.component.css

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* #docregion */
12
label {
23
border: 0;
34
clip: rect(0 0 0 0);
@@ -8,7 +9,7 @@ label {
89
position: absolute;
910
width: 1px;
1011
}
11-
12+
/* #enddocregion */
1213
input {
1314
margin-bottom: 1em;
1415
}

public/docs/_examples/cb-a11y/ts/app/form-controls/a11y-hidden-labels.component.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!-- #docregion -->
12
<div class="form-group">
23

34
<label [attr.for]="uniqueId">
@@ -11,4 +12,5 @@
1112
[attr.aria-label]="label2"
1213
class="form-control">
1314

14-
</div>
15+
</div>
16+
<!-- #enddocregion -->

public/docs/_examples/cb-a11y/ts/app/form-controls/a11y-hidden-labels.component.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Component, OnInit, Input} from "angular2/core";
22
import {A11yHelper} from "./../services/a11y-helper.service";
33

4+
// #docregion
45
@Component({
56
selector: 'a11y-hidden-labels',
67
templateUrl: './app/form-controls/a11y-hidden-labels.component.html',
@@ -19,4 +20,5 @@ export class A11yHiddenLabels implements OnInit{
1920
ngOnInit(){
2021
this.uniqueId = this._a11yHelper.generateUniqueIdString();
2122
}
22-
}
23+
}
24+
// #enddocregion

public/docs/ts/latest/cookbook/a11y.jade

+37
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ include ../_util-fns
6060

6161
So without further ado, let us see how easy it is to get big accessibility gains in our applications!
6262

63+
**Feel free to follow along in this [live example](/resources/live-examples/cb-a11y/ts/plnkr.html)**.
64+
6365
.l-main-section
6466
:marked
6567
## Important note on styling in this chapter
@@ -352,6 +354,41 @@ code-example(language="html" escape="html" format="linenums").
352354
</div>
353355
</a11y-input-explicit>
354356

357+
:marked
358+
### Hidden labels
359+
360+
Sometimes, the design of your page makes more send without a visible label. Think about `search` fields. Do you have
361+
to provide a visual label for each one?
362+
363+
The answer is no. But does that mean we get away with not labelling the field at all?
364+
365+
Once again the answer is no.
366+
367+
So how do we solve it?
368+
369+
We can either use an `explicitly labelled` input and hide the label with style, or we can use the `aria-label`, which
370+
is an `ARIA Property`.
371+
372+
**NOTE:**: We cannot hide the label using the `display` css property. Hidden fields are also hidden to assistive
373+
technologies so we have to use some css magic to either position the label outside of the visible page or
374+
shrinking it right down to be absolutely minute. We wont see it but screen readers will still find it and read it while
375+
still linking it to the correct input via the `for / id' linkup.
376+
377+
So why don't we create a component showing off both, and use the internal component styles to hide the label.
378+
379+
+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')
380+
381+
:marked
382+
Which can then be used as:
383+
384+
+makeExample('cb-a11y/ts/app/form-controls/a11y-form-controls.component.html','cb-a11y-form-controls-hidden-labels-usage')
385+
386+
:marked
387+
The way the label is rendered int he final `HTML` is no secret to us anymore, but when you inspect the second input,
388+
you will see that an `aria-label` attribute has been added to the input. Simplified:
389+
390+
code-example(language="html" escape="html" format="linenums").
391+
<input aria-label="Filter:">
355392

356393
.l-main-section
357394
<a id="keyboard-shortcuts"></a>

0 commit comments

Comments
 (0)