forked from twbs/bootstrap-sass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fancy-listbox.html
238 lines (235 loc) · 7.81 KB
/
fancy-listbox.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<!DOCTYPE html>
<html lang="en-GB">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Fancy Listbox | Talis</title>
<link
rel="stylesheet"
href="https://use.fontawesome.com/releases/v5.1.0/css/all.css"
integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt"
crossorigin="anonymous"
/>
<link
href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;600;700&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="dist/app.css" />
<link rel="icon" type="image/x-icon" href="assets/images/favicon.ico" />
<script
defer
type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"
></script>
<script
defer
type="text/javascript"
src="assets/javascripts/bootstrap.js"
></script>
<script
defer
type="text/javascript"
src="assets/javascripts/listbox.js"
></script>
<script
src="https://kit.fontawesome.com/c1ea91fe27.js"
crossorigin="anonymous"
></script>
</head>
<body>
<nav class="navbar navbar-default">
<a class="sr-only sr-only-focusable c-skip-link" href="#main-content"
>Skip to main content</a
>
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button
type="button"
class="navbar-toggle collapsed"
data-toggle="collapse"
data-target="#bs-example-navbar-collapse-1"
aria-expanded="false"
>
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/bootstrap-sass">
<img
src="assets/images/logo.png"
alt="Talis"
height="38"
/>
</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="active">
<a href="#"
>Link
<span class="sr-only">(current)</span>
</a>
</li>
<li>
<a href="error.html">View error page</a>
</li>
<li>
<a href="form.html">Example form</a>
</li>
<li>
<a href="fancy-listbox.html">Listbox</a>
</li>
<li class="dropdown">
<button
class="dropdown-toggle"
data-toggle="dropdown"
aria-haspopup="menu"
aria-expanded="false"
>
Dropdown
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>
<a href="#">Action</a>
</li>
<li>
<a href="#">Another action</a>
</li>
<li>
<a href="#">Something else here</a>
</li>
<li role="presentation" class="divider"></li>
<li>
<a href="#">Separated link</a>
</li>
<li role="presentation" class="divider"></li>
<li>
<a href="#">One more separated link</a>
</li>
</ul>
</li>
<li>
<button class="js-loader-toggle" type="button">
View loader
</button>
</li>
<li class="dropdown">
<button
class="dropdown-toggle"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
>
User Name
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>
<a href="#">Action</a>
</li>
<li>
<a href="#">Another action</a>
</li>
<li>
<a href="#">Something else here</a>
</li>
<li role="presentation" class="divider"></li>
<li>
<a href="#">Separated link</a>
</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<main class="container-fluid" id="main-content">
<section class="page-header">
<h1>Listbox Example</h1>
</section>
<section class="row">
<div class="col-md-3">
<div class="form-group">
<label id="listbox-label">Select a resource type</label>
<div class="c-fancy-listbox js-listbox-wrapper">
<button
class="
btn btn-primary btn-block
dropdown-toggle
c-fancy-listbox__toggle
js-listbox-toggle
"
aria-haspopup="listbox"
aria-labelledby="listbox-label listbox-button"
id="listbox-button"
type="button"
data-toggle="dropdown"
>
<span class="c-fancy-listbox__toggle__value js-listbox-value">
<i class="fal fa-book"></i>
<span>Book</span>
</span>
<span class="caret"></span>
</button>
<ul
id="listbox-list"
tabindex="-1"
role="listbox"
aria-labelledby="listbox-label"
class="dropdown-menu c-fancy-listbox__dropdown"
>
<li id="listbox-resource-book" role="option">
<i class="fal fa-book fa-2x"></i>
<span>Book</span>
</li>
<li id="listbox-resource-article" role="option">
<i class="fal fa-newspaper fa-2x"></i>
<span>Journal article</span>
</li>
<li id="listbox-resource-score" role="option">
<i class="fal fa-list-music fa-2x"></i>
<span>Music score</span>
</li>
</ul>
</div>
</div>
</div>
<div class="col-md-9">
<div class="row">
<div class="col">
<h2>Notes</h2>
<ul>
<li>Two widgets - the listbox itself and the toggle to hide/show</li>
<li>Lots of keyboard handling required.</li>
<li>Needs to track <code>activedescendant</code> so that focus can start at correct item</li>
<li>Why don't we just use a <code><select></code></li>
</ul>
</div>
</div>
<div class="row">
<div class="col">
<h2>Gist</h2>
<script src="https://gist.github.com/danielmatthew/21bf018b0e39e2324dd017fbceae110c.js"></script>
</div>
</div>
</div>
</section>
</main>
<script>
window.addEventListener("load", function () {
const button = document.getElementById("listbox-button");
const listbox = new Listbox(
document.querySelector('[role="listbox"]')
);
const listboxButton = new ListboxButton(button, listbox);
});
</script>
</body>
</html>