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

Commit ed88b77

Browse files
committed
doc(cb-a11y): Labelling form controls: content
1 parent b49f4c4 commit ed88b77

File tree

5 files changed

+159
-145
lines changed

5 files changed

+159
-145
lines changed

public/docs/_examples/cb-a11y/ts/a11y.css

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ hr {
1212
color: #fff;
1313
}
1414

15+
.visually-hidden {
16+
border: 0;
17+
clip: rect(0 0 0 0);
18+
height: 1px;
19+
margin: -1px;
20+
overflow: hidden;
21+
padding: 0;
22+
position: absolute;
23+
width: 1px;
24+
}
25+
1526
/*This is a copy of the .form-control class in bootstrap
1627
to enable adding it to all form controls without to much
1728
noise in the examples.*/
@@ -32,4 +43,4 @@ noise in the examples.*/
3243
/*-webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;*/
3344
/*-o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;*/
3445
/*transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;*/
35-
/*}*/
46+
/*}*/

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

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,25 @@ <h3>Implicit labeling</h3>
99
<hr>
1010
</header>
1111

12+
<!-- #docregion cb-a11y-form-controls-input-implicit -->
1213
<div class="form-group">
1314
<label>Type something:
1415
<input class="form-control"
1516
[(ngModel)]="inputModel">
1617
</label>
1718
</div>
19+
<!-- #enddocregion -->
1820

21+
<!-- #docregion cb-a11y-form-controls-textarea-implicit -->
1922
<div class="form-group">
2023
<label>Type some text:
2124
<input class="form-control"
2225
[(ngModel)]="textModel">
2326
</label>
2427
</div>
28+
<!-- #enddocregion -->
2529

30+
<!-- #docregion cb-a11y-form-controls-checkboxes-implicit -->
2631
<fieldset class="form-group row">
2732
<legend class="col-xs-12">
2833
What do you like most about Angular 2?
@@ -37,7 +42,9 @@ <h3>Implicit labeling</h3>
3742
</label>
3843
</div>
3944
</fieldset>
45+
<!-- #enddocregion -->
4046

47+
<!-- #docregion cb-a11y-form-controls-radiobuttons-implicit -->
4148
<fieldset class="form-group row">
4249
<legend class="col-xs-12">
4350
Choose your favourite Angular 2 language
@@ -54,7 +61,9 @@ <h3>Implicit labeling</h3>
5461
</label>
5562
</div>
5663
</fieldset>
64+
<!-- #enddocregion -->
5765

66+
<!-- #docregion cb-a11y-form-controls-select-implicit -->
5867
<div class="form-group">
5968
<label>Why are interested in a11y?
6069
<select class="form-control"
@@ -66,6 +75,7 @@ <h3>Implicit labeling</h3>
6675
</select>
6776
</label>
6877
</div>
78+
<!-- #enddocregion -->
6979

7080
<button class="btn btn-primary" (click)="submitMe()">Submit</button>
7181

@@ -77,6 +87,7 @@ <h3>Explicit labeling</h3>
7787
<hr>
7888
</header>
7989

90+
<!-- #docregion cb-a11y-form-controls-input-explicit -->
8091
<div class="form-group">
8192
<label for="inputexplicit">
8293
Label for input:
@@ -85,66 +96,43 @@ <h3>Explicit labeling</h3>
8596
[(ngModel)]="inputExplicitModel"
8697
class="form-control">
8798
</div>
99+
<!-- #enddocregion -->
88100

89101
<button class="btn btn-primary" (click)="submitMe()">Submit</button>
90102

91103
</section>
92104

93-
<!--<section class="row well">-->
94-
<!--<header>-->
95-
<!--<h3>Implicit labeling</h3>-->
96-
<!--<hr>-->
97-
<!--</header>-->
98-
99-
<!--&lt;!&ndash; #docregion cb-a11y-form-controls-input-usage &ndash;&gt;-->
100-
<!--<a11y-input>Type something:</a11y-input>-->
101-
<!--&lt;!&ndash;#enddocregion&ndash;&gt;-->
102-
103-
<!--&lt;!&ndash; #docregion cb-a11y-form-controls-textarea-usage &ndash;&gt;-->
104-
<!--<a11y-textarea>Type some text:</a11y-textarea>-->
105-
<!--&lt;!&ndash;#enddocregion&ndash;&gt;-->
106-
107-
<!--&lt;!&ndash; #docregion cb-a11y-form-controls-checkboxes-usage &ndash;&gt;-->
108-
<!--<a11y-checkboxes [checkboxModel]="checkBoxes" [checkboxName]="'likes'">-->
109-
<!--What do you like most about Angular 2?-->
110-
<!--</a11y-checkboxes>-->
111-
<!--&lt;!&ndash;#enddocregion&ndash;&gt;-->
112-
113-
<!--&lt;!&ndash; #docregion cb-a11y-form-controls-radiobuttons-usage &ndash;&gt;-->
114-
<!--<a11y-radiobuttons [radiobuttonModel]="radioButtons" [radiobuttonName]="'language'">-->
115-
<!--Choose your favourite Angular 2 language:-->
116-
<!--</a11y-radiobuttons>-->
117-
<!--&lt;!&ndash;#enddocregion&ndash;&gt;-->
118-
119-
<!--&lt;!&ndash; #docregion cb-a11y-form-controls-select-usage &ndash;&gt;-->
120-
<!--<a11y-select [optionsModel]="selectOptions">Why are you interested in a11y?</a11y-select>-->
121-
<!--&lt;!&ndash;#enddocregion&ndash;&gt;-->
122-
123-
<!--</section>-->
124-
<!--<section class="row well">-->
125-
<!--<header>-->
126-
<!--<h3>Explicit labeling</h3>-->
127-
<!--<hr>-->
128-
<!--</header>-->
129-
130-
<!--&lt;!&ndash; #docregion cb-a11y-form-controls-input-explicit-usage &ndash;&gt;-->
131-
<!--<a11y-input-explicit> Label for input:</a11y-input-explicit>-->
132-
<!--&lt;!&ndash;#enddocregion&ndash;&gt;-->
133-
134-
<!--</section>-->
135105
<section class="row well">
136106
<header>
137107
<h3>Hiding labels</h3>
138108
<hr>
139109
</header>
140110

141-
<!-- #docregion cb-a11y-form-controls-hidden-labels-usage -->
142-
<a11y-hidden-labels [label1]="'Search:'"
143-
[label2]="'Filter:'">
144-
</a11y-hidden-labels>
145-
<!--#enddocregion-->
111+
<!-- #docregion cb-a11y-form-controls-hidden-label-explicit -->
112+
<div class="form-group">
113+
<label class="visually-hidden" for="inputsearch">
114+
Search:
115+
</label>
116+
<input id="inputsearch"
117+
[(ngModel)]="searchModel"
118+
placeholder="Search... (Label hidden with style)"
119+
class="form-control">
120+
</div>
121+
<!-- #enddocregion -->
122+
123+
<!-- #docregion cb-a11y-form-controls-hidden-label-aria -->
124+
<div class="form-group">
125+
<input placeholder="Filter... (Labelled with aria-label)"
126+
[(ngModel)]="filterModel"
127+
aria-label="Filter:"
128+
class="form-control">
129+
</div>
130+
<!-- #enddocregion -->
131+
132+
<button class="btn btn-primary" (click)="submitMe()">Submit</button>
146133

147134
</section>
135+
148136
<section class="row well">
149137
<header>
150138
<h3>Labeling custom controls</h3>

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ export class A11yFormControls implements OnInit {
3737
inputModel:string;
3838
inputExplicitModel: string;
3939
textModel:string;
40-
radioModel:string = '2';
41-
checkboxModel:Array<string> = ["1", "2"];
4240
selectModel: string;
41+
searchModel: string;
42+
filterModel: string;
4343

44+
radioModel:string = '2';
45+
checkboxModel:Array<string> = ["1", "2"];
4446

4547

4648
constructor(private _a11yHelper:A11yHelper) {
@@ -53,26 +55,22 @@ export class A11yFormControls implements OnInit {
5355
console.log(this.radioModel);
5456
console.log(this.selectModel);
5557
console.log(this.inputExplicitModel);
58+
console.log(this.searchModel);
59+
console.log(this.filterModel);
5660
}
5761

58-
isChecked(entry:string):boolean {
59-
return this.checkboxModel.indexOf(entry.toString()) != -1;
62+
isChecked(item:string):boolean {
63+
return this._a11yHelper.isStringInArray(this.checkboxModel, item);
6064
}
6165

62-
toggleCheckbox(entry:string):void {
63-
var entryIndex = this.checkboxModel.indexOf(entry);
64-
if (entryIndex != -1) {
65-
this.checkboxModel.splice(entryIndex, 1);
66-
} else {
67-
this.checkboxModel.push(entry);
68-
}
66+
toggleCheckbox(item:string):void {
67+
this._a11yHelper.toggleItemInArray(this.checkboxModel, item);
6968
}
7069

7170
ngOnInit() {
7271
this.checkBoxes = this._a11yHelper.getCheckboxModel();
7372
this.radioButtons = this._a11yHelper.getRadiobuttonsModel();
7473
this.selectOptions = this._a11yHelper.getSelectOptions();
75-
7674
}
7775

7876
}

public/docs/_examples/cb-a11y/ts/app/services/a11y-helper.service.ts

Lines changed: 82 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,77 +2,90 @@ import {Injectable} from "angular2/core";
22

33
@Injectable()
44
export class A11yHelper {
5-
generateUniqueIdString():string {
6-
return (this.randomGuidSnippet() +
7-
this.randomGuidSnippet() + "-" +
8-
this.randomGuidSnippet() + "-4" +
9-
this.randomGuidSnippet().substr(0, 3) + "-" +
10-
this.randomGuidSnippet() + "-" +
11-
this.randomGuidSnippet() +
12-
this.randomGuidSnippet() +
13-
this.randomGuidSnippet()).toLowerCase();
14-
}
5+
generateUniqueIdString():string {
6+
return (this.randomGuidSnippet() +
7+
this.randomGuidSnippet() + "-" +
8+
this.randomGuidSnippet() + "-4" +
9+
this.randomGuidSnippet().substr(0, 3) + "-" +
10+
this.randomGuidSnippet() + "-" +
11+
this.randomGuidSnippet() +
12+
this.randomGuidSnippet() +
13+
this.randomGuidSnippet()).toLowerCase();
14+
}
1515

16-
getCheckboxModel():any {
17-
return [
18-
{
19-
name: 'Template syntax',
20-
value: 0
21-
},
22-
{
23-
name: 'Observables',
24-
value: 1
25-
},
26-
{
27-
name: 'Components',
28-
value: 2
29-
},
30-
{
31-
name: 'Forms',
32-
value: 3
33-
}
34-
];
35-
}
16+
getCheckboxModel():any {
17+
return [
18+
{
19+
name: 'Template syntax',
20+
value: 0
21+
},
22+
{
23+
name: 'Observables',
24+
value: 1
25+
},
26+
{
27+
name: 'Components',
28+
value: 2
29+
},
30+
{
31+
name: 'Forms',
32+
value: 3
33+
}
34+
];
35+
}
3636

37-
getRadiobuttonsModel():any {
38-
return [
39-
{
40-
name: 'TypeScript',
41-
value: 0
42-
},
43-
{
44-
name: 'JavaScript',
45-
value: 1
46-
},
47-
{
48-
name: 'ES6',
49-
value: 2
50-
},
51-
{
52-
name: 'Dart',
53-
value: 3
54-
}
55-
];
56-
}
37+
getRadiobuttonsModel():any {
38+
return [
39+
{
40+
name: 'TypeScript',
41+
value: 0
42+
},
43+
{
44+
name: 'JavaScript',
45+
value: 1
46+
},
47+
{
48+
name: 'ES6',
49+
value: 2
50+
},
51+
{
52+
name: 'Dart',
53+
value: 3
54+
}
55+
];
56+
}
5757

58-
getSelectOptions(): any {
59-
return [
60-
{
61-
name: 'Curiosity',
62-
value: 0
63-
},
64-
{
65-
name: 'Increased userbase',
66-
value: 1
67-
},
68-
{
69-
name: 'Legal reasons',
70-
value: 2
71-
}
72-
];
73-
}
58+
getSelectOptions():any {
59+
return [
60+
{
61+
name: 'Curiosity',
62+
value: 0
63+
},
64+
{
65+
name: 'Increased userbase',
66+
value: 1
67+
},
68+
{
69+
name: 'Legal reasons',
70+
value: 2
71+
}
72+
];
73+
}
7474

75-
private randomGuidSnippet():string {
76-
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
75+
toggleItemInArray(stringArray:Array<string>, item:string): void {
76+
var entryIndex = stringArray.indexOf(item);
77+
if (entryIndex != -1) {
78+
stringArray.splice(entryIndex, 1);
79+
} else {
80+
stringArray.push(item);
7781
}
78-
}
82+
}
83+
84+
isStringInArray(stringArray: Array<string>, item: string): boolean {
85+
return stringArray.indexOf(item.toString()) != -1;
86+
}
87+
88+
private randomGuidSnippet():string {
89+
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
90+
}
91+
}

0 commit comments

Comments
 (0)