-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
273 lines (239 loc) · 10.2 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
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<!DOCTYPE HTML>
<html lang="en-us" class="no-js">
<head>
<meta charset="utf-8">
<title>
ARIA Disclosure Widget
</title>
<meta name="viewport"
content="width=device-width, initial-scale=1">
<script>
// remove no-js and add 'js' to the HTML
document.documentElement.className = document.documentElement.className.replace('no-js', 'js');
</script>
<link rel="stylesheet" href="assets/css/--demo--.css">
<link rel="stylesheet" href="assets/css/custom-disclosure.css">
<style>
body {
padding: 2em;
}
</style>
</head>
<body id="body">
<div id="page" class="page">
<header>
<h1>
<abbr title="Accessible Rich Internet Applications">ARIA</abbr>
Disclosure Widgets
</h1>
<p>
A test page for different disclosure widgets you can make with this script.
</p>
<p>
Check out the <a href="https://github.com/scottaohara/aria_disclosure_widget">GitHub repo for this demo</a>.
</p>
</header>
<main>
<section>
<h2>Standard disclosure widgets</h2>
<p>
Use either <code>disclosure-inline</code> (for <code>display: inline-block</code>) or
<code>disclosure-block</code> (for <code>display: block</code>) custom elements as the wrappers.
</p>
<p>
Either wrapping element <strong>must</strong> contain a <code><disclosure-content></code> element.
This element represents the content you want to show/hide.
</p>
<p>
A trigger (<code><button></code> element) will be auto-generated with the fallback text of "More info".
</p>
<pre role="group" aria-label="code example"><code><disclosure-inline>
<disclosure-content>
...
</disclosure-content>
</disclosure-inline></code></pre>
<p><code>disclosure-inline</code></p>
<disclosure-inline>
<disclosure-content>
If the script didn't run, this content would have just been hanging out there for you to read.
</disclosure-content>
</disclosure-inline>
<pre role="group" aria-label="code example"><code><disclosure-block>
<disclosure-content>
...
</disclosure-content>
</disclosure-block></code></pre>
<p><code>disclosure-block</code></p>
<disclosure-block>
<disclosure-content>
If the script didn't run, this content would have just been hanging out there for you to read.
</disclosure-content>
</disclosure-block>
<h3>Give your triggers unique labels</h3>
<p>
Use the <code>data-trigger</code> attribute on the disclosure parent element to specify a name for
the auto-generated trigger (<code><button></code> element).
</p>
<pre role="group" aria-label="code example"><code><disclosure-inline
data-trigger="My Name!!!">
...
</disclosure-inline></code></pre>
<p>
<disclosure-inline data-trigger="My Name!!!">
<disclosure-content>
If the script didn't run, this content would have just been hanging out there for you to read.
</disclosure-content>
</disclosure-inline>
</p>
<h3>Adjust the down arrow position</h3>
<p>
Use the <code>data-left-align</code> attribute to have the down arrow / chevron appear prior to the trigger's visible label.
</p>
<div>
<disclosure-inline data-left-align data-trigger="And one with a left-aligned arrow">
<disclosure-content>
If the script didn't run, this content would have just been hanging out there for you to read.
</disclosure-content>
</disclosure-inline>
</div>
<h3>Identify where to generate the trigger</h3>
<p>
Maybe you need more flexibility on where your disclosure widget trigger is generated.
Use the <code>data-insert-trigger</code> attribute to override the default placement,
and instead inject the trigger into that particular element.
</p>
<disclosure-block id="ex">
<p>
This text exists as the first child element of the <code>disclosure-block</code>.
Following this paragraph is a <code><div data-insert-trigger></code>.
The trigger will be injected into that element.
</p>
<div data-insert-trigger>
Find out more
</div>
<disclosure-content>
<p>
As another example, what follows is a nested disclosure widget, but its trigger
has been disabled by default (using the <code>data-disabled</code> attribute on
the parent <code><disclosure-inline></code> element).
</p>
<p>
<a href="#!">
This link is here just for focus testing.
</a>
</p>
<disclosure-inline id="ex2a" data-disabled data-trigger="I don't work">
<disclosure-content>
<p>
Hey! You weren't supposed to get to me...
</p>
</disclosure-content>
</disclosure-inline>
</disclosure-content>
</disclosure-block>
<h4>Make it 'pop'</h4>
<p>
Use the <code>data-popup</code> attribute to have the disclosure widget content absolutely positioned.
The popup content will allow for keyboard focus to enter it and interact with the content.
Tabbing away will close the disclosure widget. The <kbd>Esc</kbd> key will also close the disclosure widget
when keyboard focus is on the trigger, or within the disclosure widget's content panel.
</p>
<pre role="group" aria-label="code example"><code><disclosure-inline data-popup>
<disclosure-content role=note>
...
</disclosure-content>
</disclosure-inline></code></pre>
<disclosure-inline data-trigger="Let's make it pop" data-popup>
<disclosure-content role="note">
<p>I have a <code>role=note</code>. You don't have to add this, but if you'd like to learn more about this role, <a href="https://www.w3.org/TR/wai-aria-1.2/#note">check out the ARIA specification</a>.</p>
</disclosure-content>
</disclosure-inline>
<h4>Inject a trigger into a heading</h4>
<p>
The following are some examples of ways to have a disclosure widget trigger within a heading.
The first of which is a button as a sibling to the heading's text.
</p>
<p>
The second example is a button that takes the entirety of the heading's content and includes it as
child content of the injected button element. <strong>Make sure</strong> you use this with caution,
as you don't want links or other interactive elements as child elements to the injected button.
</p>
<pre role="group" aria-label="code example"><code><disclosure-inline>
<h5>
Heading with adjacent toggle
<span data-insert-trigger="inline"></span>
</h5>
<disclosure-content>
...
</disclosure-content>
</disclosure-inline></code></pre>
<disclosure-inline id="ex2">
<h5 style="margin-bottom: 0;">
Heading with adjacent toggle
<span data-insert-trigger="inline"></span>
</h5>
<disclosure-content>
<p>
Sometimes you don't want your full heading to be clickable. Sometimes.
</p>
</disclosure-content>
</disclosure-inline>
<pre role="group" aria-label="code example"><code><disclosure-block data-open>
<h5 data-insert-trigger>
<img src=... alt style=...>
<span style=...>...</span>
</h5>
<disclosure-content>
...
</disclosure-content>
</disclosure-block></code></pre>
<div>
<disclosure-block data-open class="test-class">
<h5 data-insert-trigger>
<img src="assets/test.svg" alt=""
style="width: 2em; height: 2em;
vertical-align: middle;
background: #fff;
border-radius: 100%;
overflow: hidden;
margin-right: .25em;
border: 1px solid #000;">
<span style="vertical-align: middle;">Disclosure button within a heading</span>
</h5>
<disclosure-content>
<p>
This disclosure widget is opened by default.
Because that's a thing that should be able to happen.
</p>
<div>
<p>Here's an example of a nested popup disclosure widget:</p>
<disclosure-inline data-trigger="I have a popup!" data-popup data-inline>
<disclosure-content>
<p>
This example has a <a href="#">link within it</a>.
popups can be closed via the <kbd>Esc</kbd> key, as
long as focus is on the <code><button></code> or within
the revealed content.
</p>
<p>
popups will auto-close if focus leaves the popup.
</p>
</disclosure-content>
</disclosure-inline>
</div>
</disclosure-content>
</disclosure-block>
</div>
</section>
</main>
</div>
<script src="index.js"></script>
<script>
const els = document.querySelectorAll('disclosure-inline, disclosure-block');
// Generate all disclosure instances
for ( let i = 0; i < els.length; i++ ) {
ARIAdw(els[i])
}
</script>
</body>
</html>