-
Notifications
You must be signed in to change notification settings - Fork 0
/
combobox-examples.html
203 lines (181 loc) · 11 KB
/
combobox-examples.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Combobox Examples</title>
<!-- Style Sheets -->
<style>
.hide-me {
position: relative;
}
.hide-me select,
.hide-me label {
position: absolute;
left: -999em;
}
</style>
</head>
<body>
<h1>Combobox</h1>
<h2>Example 1: HTML <code>select</code> and <code>option</code> elements</h2>
<h3>Working <code>select</code> box</h3>
<p>The <code>select</code> element is identified as having pop-up menu, and the popped-up menu (i.e., the box of options) cannot be positioned off screen.</p>
<label for="solute1-options">Solute 1:</label>
<select id="solute1-options" name="solute1-options">
<option value="1">Drink mix</option>
<option value="2">Cobalt (II) nitrate</option>
<option value="3">Cobalt Chloride</option>
<option value="4">Potassium dichromate</option>
<option value="5">Gold (III) chloride</option>
<option value="6">Potassium chromate</option>
<option value="7">Nickel (II) chloride</option>
<option value="8">Copper sulfate</option>
<option value="9">Potassium permanganate</option>
<option value="10">Potassium dichromate</option>
</select>
<h3>Working Hidden <code>select</code> box</h3>
<div class="hide-me">
<label for="solute2-options">Hidden solutes:</label>
<select id="solute2-options" name="solute2-options" size="10">
<option value="1">Drink mix</option>
<option value="2">Cobalt (II) nitrate</option>
<option value="3">Cobalt Chloride</option>
<option value="4">Potassium dichromate</option>
<option value="5">Gold (III) chloride</option>
<option value="6">Potassium chromate</option>
<option value="7">Nickel (II) chloride</option>
<option value="8">Copper sulfate</option>
<option value="9">Potassium permanganate</option>
<option value="10">Potassium dichromate</option>
</select>
</div>
<h3>Code for hidden <code>select</code> box</h3>
<p>With the size attribute, the box of options stays open, seems to behave like it has the ARIA role <code>listbox</code>, and can be successfully positioned off screen.</p>
<pre>
<label for="solute-options">Hidden solutes:</label>
<select id="solute-options" name="solute-options" size="10">
<option value="1">Drink mix</option>
<option value="2">Cobalt (II) nitrate</option>
<option value="3">Cobalt Chloride</option>
<option value="4">Potassium dichromate</option>
<option value="5">Gold (III) chloride</option>
<option value="6">Potassium chromate</option>
<option value="7">Nickel (II) chloride</option>
<option value="8">Copper sulfate</option>
<option value="9">Potassium permanganate</option>
<option value="10">Potassium dichromate</option>
</select>
</pre>
<h2>Example 2: ARIA 1.0 Design Pattern</h2>
<p>See <a href="http://whatsock.com/tsg/Coding%20Arena/ARIA%20Comboboxes/ARIA%20Comboboxes%20(Simulated,%20Readonly)/demo.htm">Whatsock for a working example</a>. This is the pattern I tried to follow.</p>
<p><strong>Note: </strong>Behaviour not prgrammed in.</p>
<h3>Non-working <code>combobox</code> widget</h3>
<input id="solute2-comboxbox" tabindex="0" aria-label="Solute 2" type="text" role="combobox" aria-expanded="false" aria-autocomplete="list" aria-controls="owned-solute-listbox" readonly>
<ul role="listbox" id="owned-solute-listbox" aria-labelledby="solute2-comboxbox solute-option-01">
<li role="option" id="solute-option-01">Drink mix</li>
<li role="option" id="solute-option-02">Cobalt (II) nitrate</li>
<li role="option" id="solute-option-03">Cobalt Chloride</li>
<li role="option" id="solute-option-04">Potassium dichromate</li>
<li role="option" id="solute-option-05">Gold (III) chloride</li>
<li role="option" id="solute-option-06">Potassium chromate</li>
<li role="option" id="solute-option-07">Nickel (II) chloride</li>
<li role="option" id="solute-option-08">Copper sulfate</li>
<li role="option" id="solute-option-09">Potassium permanganate</li>
<li role="option" id="solute-option-10">Potassium dichromate</li>
</ul>
<h3>Code for <code>combobox</code> widget</h3>
<pre>
<input id="solute-comboxbox" tabindex="0" aria-label="Solute" type="text"
role="combobox" aria-expanded="false" aria-autocomplete="list"
aria-controls="owned-solute-listbox" aria-activedescendent="solute-option-02" readonly>
<ul role="listbox" id="owned-solute-listbox" aria-labelledby="solute2-comboxbox solute-option-01">
<li role="option" id="solute-option-01">Drink mix</li>
<li role="option" id="solute-option-02">Cobalt (II) nitrate</li>
<li role="option" id="solute-option-03">Cobalt Chloride</li>
<li role="option" id="solute-option-04">Potassium dichromate</li>
<li role="option" id="solute-option-05">Gold (III) chloride</li>
<li role="option" id="solute-option-06">Potassium chromate</li>
<li role="option" id="solute-option-07">Nickel (II) chloride</li>
<li role="option" id="solute-option-08">Copper sulfate</li>
<li role="option" id="solute-option-09">Potassium permanganate</li>
<li role="option" id="solute-option-10">Potassium dichromate</li>
</ul>
</pre>
<h2>Example 3: Listbox Design Pattern</h2>
<p>Code from <a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_listbox_role">MDN Listbox Example</a>. This example as-is does not read out the label, "Solute 3", as the listbox's label on focus. The listbox always seems to be annouced upon leaving the listbox, but not always upon entering it. The full Keyboard design pattern is not programmed in, either.</p>
<p><strong>Note:</strong> Added second <code>aria-labelledby</code> and now both</p>
<div id="label-listbox1">Solute 3</div>
<div role="listbox" tabindex="0" id="listbox1" onclick="return listItemClick(event);"
onkeydown="return listItemKeyEvent(event);" onkeypress="return listItemKeyEvent(event);"
onfocus="this.className='focus';" onblur="this.className='blur';" aria-activedescendant="listbox1-2" aria-labelledby="label-listbox1 listbox1-2">
<div role="option" id="listbox1-1">Drink mix</div>
<div role="option" id="listbox1-2" class="selected" aria-selected="true">Cobalt (II) nitrate</div>
<div role="option" id="listbox1-3">Cobalt Chloride</div>
<div role="option" id="listbox1-4">Potassium dichromate</div>
<div role="option" id="listbox1-5">Gold (III) chloride</div>
<div role="option" id="listbox1-6">Potassium chromate</div>
<div role="option" id="listbox1-7">Nickel (II) chloride</div>
<div role="option" id="listbox1-8">Copper sulfate</div>
<div role="option" id="listbox1-9">Potassium permanganate</div>
<div role="option" id="listbox1-10">Potassium dichromate</div>
</div>
<h2>Example 4: Listbox as an un-ordered list</h2>
<p>Same code from <a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_listbox_role">MDN Listbox Example</a>, but using in this example, I'm using a heading and list structure. This example as-is does not read out the <code>h3</code> heading "Solute 4" as the label for the listbox. The listbox always seems to be annouced upon leaving the listbox, but not always upon entering it. The full Keyboard design pattern is not programmed in here, either.</p>
<h3 id="label-listbox4">Solute 4</h3>
<ul role="listbox" tabindex="0" id="listbox4" onclick="return listItemClick(event);"
onkeydown="return listItemKeyEvent(event);" onkeypress="return listItemKeyEvent(event);"
onfocus="this.className='focus';" onblur="this.className='blur';" aria-activedescendant="listbox4-4" aria-labelledby="label-listbox4 listbox4-4" style="list-style:none;">
<li role="option" id="listbox4-1">Drink mix</li>
<li role="option" id="listbox4-2">Cobalt (II) nitrate</li>
<li role="option" id="listbox4-3">Cobalt Chloride</li>
<li role="option" id="listbox4-4" class="selected" aria-selected="true">Potassium dichromate</li>
<li role="option" id="listbox4-5">Gold (III) chloride</li>
<li role="option" id="listbox4-6">Potassium chromate</li>
<li role="option" id="listbox4-7">Nickel (II) chloride</li>
<li role="option" id="listbox4-8">Copper sulfate</li>
<li role="option" id="listbox4-9">Potassium permanganate</li>
<li role="option" id="listbox4-10">Potassium dichromate</li>
</ul>
<h3>Code for Example 4 <code>listbox</code> widget</h3>
<pre>
<h3 id="label-listbox4">Solute 4</h3>descendent="" readonly>
<ul role="listbox" tabindex="0" id="listbox4"
onclick="return listItemClick(event);"
onkeydown="return listItemKeyEvent(event);"
onkeypress="return listItemKeyEvent(event);"
onfocus="this.className='focus';" onblur="this.className='blur';"
aria-activedescendant="listbox4-4"
aria-labelledby="label-listbox4 listbox4-4"
style="list-style:none;">
<li role="option" id="listbox4-1">Drink mix</li>
<li role="option" id="listbox4-2">Cobalt (II) nitrate</li>
<li role="option" id="listbox4-3">Cobalt Chloride</li>
<li role="option" id="listbox4-4" class="selected" aria-selected="true">Potassium dichromate</li>
<li role="option" id="listbox4-5">Gold (III) chloride</li>
<li role="option" id="listbox4-6">Potassium chromate</li>
<li role="option" id="listbox4-7">Nickel (II) chloride</li>
<li role="option" id="listbox4-8">Copper sulfate</li>
<li role="option" id="listbox4-9">Potassium permanganate</li>
<li role="option" id="listbox4-10">Potassium dichromate</li>
</ul>
</pre>
<h2>Example 5: Button with dynamic inner content & Listbox as an un-ordered list</h2>
<p>Adpated from <a href="https://www.w3.org/TR/wai-aria-practices/examples/listbox/listbox-collapsible.html">collapsible listbox example</a></p>
<div tabindex="-1" id="container-4-59-414-303-307">
<span id="listbox5-static-label">Solute</span>
<button id="listbox5-dynamic-label" tabindex="0" aria-haspopup="listbox" aria-labelledby="listbox5-static-label listbox5-dynamic-label">Drink Mix</button>
</div>
<ul role="listbox" tabindex="-1" id="listbox5" aria-activedescendant="listbox5-1" aria-labelledby="listbox5-static-label" style="list-style:none;">
<li role="option" id="listbox5-1" class="selected" aria-selected="true">Drink mix</li>
<li role="option" id="listbox5-2">Cobalt (II) nitrate</li>
<li role="option" id="listbox5-3">Cobalt Chloride</li>
<li role="option" id="listbox5-4">Potassium dichromate</li>
<li role="option" id="listbox5-5">Gold (III) chloride</li>
<li role="option" id="listbox5-6">Potassium chromate</li>
<li role="option" id="listbox5-7">Nickel (II) chloride</li>
<li role="option" id="listbox5-8">Copper sulfate</li>
<li role="option" id="listbox5-9">Potassium permanganate</li>
<li role="option" id="listbox5-10">Potassium dichromate</li>
</ul>
</body>
</html>