-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
174 lines (149 loc) · 6.53 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<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">
<link rel="stylesheet" href="./style.css">
<title>Accessible Dropdown</title>
</head>
<body>
<div class="wrapper">
<h1>Accessible Dropdown</h1>
<p class="back">
<a href="../../index.html">Back to components list</a>
</p>
<h2>Demo</h2>
<h3>Non automatic selection</h3>
<div id="dropdown-1" class="dropdown">
<span class="dropdown__label">Choose an element</span>
<button aria-haspopup="listbox">Choose an element</button>
<ul tabindex="-1" role="listbox">
<li role="option">Book</li>
<li role="option">Movies</li>
<li role="option">Music</li>
<li role="option">Video games</li>
<li role="option">Paint</li>
</ul>
</div>
<h3>Automatic first item selected</h3>
<div id="dropdown-2" class="dropdown">
<span class="dropdown__label">Choose an element</span>
<button aria-haspopup="listbox">Choose an element</button>
<ul tabindex="-1" role="listbox">
<li role="option">Book</li>
<li role="option">Movies</li>
<li role="option">Music</li>
<li role="option">Video games</li>
<li role="option">Paint</li>
</ul>
</div>
<h3>Automatic specific item selected</h3>
<div id="dropdown-3" class="dropdown">
<span class="dropdown__label">Choose an element</span>
<button aria-haspopup="listbox">Choose an element</button>
<ul tabindex="-1" role="listbox">
<li role="option">Book</li>
<li role="option">Movies</li>
<li role="option" class="current">Music</li>
<li role="option">Video games</li>
<li role="option">Paint</li>
</ul>
</div>
<h3>With events</h3>
<div id="dropdown-4" class="dropdown">
<span class="dropdown__label">Choose an element</span>
<button aria-haspopup="listbox">Choose an element</button>
<ul tabindex="-1" role="listbox">
<li role="option">Book</li>
<li role="option">Movies</li>
<li role="option">Music</li>
<li role="option">Video games</li>
<li role="option">Paint</li>
</ul>
</div>
<h3>Dropdown only for < 1024px devices</h3>
<div id="dropdown-5" class="dropdown">
<span class="dropdown__label">Choose an element</span>
<button aria-haspopup="listbox">Choose an element</button>
<ul tabindex="-1" role="listbox">
<li role="option">Book</li>
<li role="option">Movies</li>
<li role="option">Music</li>
<li role="option">Video games</li>
<li role="option">Paint</li>
</ul>
</div>
<h3>Action buttons</h3>
<div id="dropdown-6" class="dropdown">
<span class="dropdown__label">Choose an element</span>
<button aria-haspopup="listbox">Choose an element</button>
<ul tabindex="-1" role="listbox">
<li role="option">Book</li>
<li role="option">Movies</li>
<li role="option">Music</li>
<li role="option">Video games</li>
<li role="option">Paint</li>
</ul>
</div>
<button id="add">Add a dummy item</button>
<button id="remove">Remove the first item</button>
<button id="remove-all">Remove all items</button>
<h2>Code</h2>
<p class="codepen" data-height="600" data-theme-id="light" data-default-tab="html,result" data-slug-hash="VwQbYqN" data-user="beapi" style="height: 600px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;">
<span>See the Pen <a href="https://codepen.io/beapi/pen/VwQbYqN">
Accessible Collapsible Dropdown Listbox</a> by Be API (<a href="https://codepen.io/beapi">@beapi</a>)
on <a href="https://codepen.io">CodePen</a>.</span>
</p>
<script async src="https://cpwebassets.codepen.io/assets/embed/ei.js"></script>
</div>
<script type="module">
import { Dropdown } from '../../be-a11y.js'
import '../../src/css/index.css'
import './style.css'
Dropdown.preset = {
'#dropdown-1': {},
'#dropdown-2': {
automaticSelection: true,
},
'#dropdown-3': {
automaticSelection: '.current',
},
'#dropdown-4': {
onChange: function() {
alert('changed')
},
onClose: function() {
alert('closed')
},
onListItemClick: function() {
alert('List item click')
},
onOpen: function() {
alert('opened')
},
},
'#dropdown-5': {
mediaQuery: window.matchMedia('(max-width: 1024px)')
},
'#dropdown-6': {},
}
Dropdown.initFromPreset()
const addBtn = document.getElementById('add')
const removeBtn = document.getElementById('remove')
const removeAllBtn = document.getElementById('remove-all')
const dropdownInstance = Dropdown.getInstance('#dropdown-6')
addBtn.addEventListener('click', function() {
const listItem = document.createElement('li')
listItem.innerText = 'Dummy'
dropdownInstance.addItem(listItem)
})
removeBtn.addEventListener('click', function() {
dropdownInstance.removeItem(document.getElementById('dropdown-6').querySelectorAll('li')[0])
})
removeAllBtn.addEventListener('click', function() {
dropdownInstance.removeAllItems()
})
</script>
</body>
</html>