-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
358 lines (326 loc) Β· 9.88 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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
<!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">
<title>CSS Toggles demo</title>
<link rel="stylesheet" href="https://unpkg.com/open-props"/>
<link rel="stylesheet" href="/src/base.css">
<link rel="stylesheet" href="/src/styles.css">
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
</head>
<body>
<header>
<h1>CSS Toggles (in JS)</h1>
<nav>
<a href="https://css.oddbird.net/toggles/explainer/">Explainer</a>
<a href="https://tabatkins.github.io/css-toggle/">Draft Spec</a>
<a href="https://github.com/oddbird/css-toggles">Polyfill</a>
</nav>
</header>
<section>
<h2>
What are CSS Toggles?
</h2>
<p>
The goal of this (work in progress) feature
is to make it possible for CSS to manage
<em>presentational state</em>
for patterns such as tabs/accordians, carousels, color modes, etc.
There are still many questions to be answered
around the scope, syntax,
and (most importantly) accessibility
of a feature like this in CSS.
</p>
<p>
This polyfill is designed to help us
explore those questions.
It implements the
<a href="https://tabatkins.github.io/css-toggle/">draft spec syntax</a>
as currently written, where possible --
in addition to some of the
extensions proposed in our
<a href="https://css.oddbird.net/toggles/explainer/">explainer</a>.
</p>
<p class="issue">
<strong>
The current polyfill implementation is a naive attempt
to uncover and document any issues in the spec β
which means that several of the following demos
<a href="https://github.com/oddbird/css-toggles/issues?q=is%3Aissue+is%3Aopen+label%3Aa11y">
are currently inaccessible.
</a>
</strong>
While we hope that some of those issues
can be resolved here in the polyfill,
others may require changes to the spec itself,
or access to browser-internals
that cannot be polyfilled well using JS.
</p>
<p>
We're excited for you to play with this,
suggest additional use-cases,
help uncover undocumented issues,
and provide us with feedback:
</p>
<ul>
<li><a href="https://tabatkins.github.io/css-toggle/issues">
Issues related to the spec
</a></li>
<li><a href="https://github.com/oddbird/css-toggles/issues">
Issues specific to the polyfill
</a></li>
</ul>
</section>
<section id="named-modes">
<h2>
<a href="#named-modes" aria-hidden="true">π</a>
Global color toggle
</h2>
<button class="mode-btn" data-testid="mode-btn">colors</button>
<pre>html {
toggle-root: mode [auto light dark];
}
html:toggle(mode light) { ... }
html:toggle(mode dark) { ... }
.mode-btn {
toggle-trigger: mode;
}</pre>
</section>
<section id="binary-switch">
<h2>
<a href="#binary-switch" aria-hidden="true">π</a>
Binary self-toggle switches
</h2>
<p class="issue">
<a href="https://github.com/oddbird/css-toggles/issues/20">Issue 20</a>:
There's a conflict between the HTML listitem role
and the added ARIA role of 'button'
used to make these interactive.
</p>
<ul class='todo' data-testid="todo-list">
<li>write an explainer</li>
<li>draft a specification</li>
<li>create a polyfill</li>
<li>make a demo page</li>
</ul>
<pre>.todo li {
toggle: todo self;
list-style-type: 'β ';
}
.todo li:toggle(todo) {
list-style-type: 'β
';
}</pre>
</section>
<section id="accordion">
<h2>
<a href="#accordion" aria-hidden="true">π</a>
Accordion/disclosure components
</h2>
<p>
The goal of <code>toggle-visibility</code>
is for browsers to handle accessibility
and discoverability by default.
We'll keep working to improve the polyfill a11y as well,
but may not be able to achieve the same results.
</p>
<p class="issue">
<a href="https://github.com/oddbird/css-toggles/issues/20">Issue 13</a>:
While <code>aria-expanded</code> may work in some situations,
it has the same issues listed above with conflicting semantics/roles.
</p>
<dl class="accordion" data-testid="accordion">
<dt>Establish a toggle</dt>
<dd><pre>.accordion>dt {
toggle: glossary;
}</pre></dd>
<dt>Toggle item visibility</dt>
<dd><pre>.accordion>dd {
toggle-visibility: toggle glossary;
}</pre></dd>
<dt>Style the summary</dt>
<dd><pre>.accordion>dt::marker {
content: 'ππ½ ';
}
.accordion>dt:toggle(glossary) {
background-color: var(--brand);
color: var(--bg);
}
.accordion>dt:toggle(glossary)::marker {
content: 'ππ½ ';
}
</pre></dd>
</dl>
</section>
<section id="tree-view">
<h2>
<a href="#tree-view" aria-hidden="true">π</a>
Tree view
</h2>
<p class="issue">
<a href="https://github.com/oddbird/css-toggles/issues/23">Issue 23</a>:
Does 'tree view' require different semantics
than simply 'nested disclosures'
(which may better describe the current behavior)?
</p>
<ul class="tree">
<li><a href='#'>home</a></li>
<li>
<button class="nested" data-testid="resources-button">
resources
</button>
<ul data-testid="resources-branch">
<li><a href="#">articles</a></li>
<li><a href="#">demos</a></li>
<li>
<button class="nested" data-testid="media-button">
media
</button>
<ul data-testid="media-branch">
<li><a href="#">audio</a></li>
<li><a href="#">visual</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<pre>.nested {
toggle: tree;
}
.nested+ul {
toggle-visibility: toggle tree;
}</pre>
</section>
<section id="panelset">
<h2>
<a href="#panelset" aria-hidden="true">π</a>
Tabs or exclusive accordions
</h2>
<ul>
<li class="issue">
<a href="https://github.com/oddbird/css-toggles/issues/9">Issue 9</a>:
Not possible to change initial state for one toggle in a group.
</li>
<li class="issue">
<a href="https://github.com/oddbird/css-toggles/issues/13">Issue 13</a>:
In this case,
the expected a11y handling requires the
<code>tab</code> role
and <code>aria-selected</code>.
Is there a way to clearly support both
disclosure and tab a11y using this shared syntax?
</li>
</ul>
<panel-set data-testid="tabs">
<panel-tab>Establishing Tabs</panel-tab>
<panel-card><pre>panel-tab {
toggle: tab 1 at 0 group sticky;
grid-row: tab;
}</pre></panel-card>
<panel-tab>Styling Content</panel-tab>
<panel-card><pre>panel-tab:toggle(tab) {
background-color: var(--callout);
}
panel-card {
toggle-visibility: toggle tab;
grid-area: card;
}</pre></panel-card>
</panel-set>
</section>
<section id="named-colors">
<h2>
<a href="#named-colors" aria-hidden="true">π</a>
Named states
</h2>
<p class="issue">
<a href="https://github.com/oddbird/css-toggles/issues/21">Issue 21</a>:
These act like radio buttons,
but the proper a11y handling is not obvious from the syntax.
</p>
<div class="colors" data-testid="colors">
<button>Cycle</button>
<button class="grape">Grape</button>
<button class="green">Green</button>
<button class="blue">Blue</button>
<button class="red">Red</button>
<pre class="show-colors" data-testid="colors-target">.colors {
toggle-root: colors [grape green blue red] at blue;
}
.colors button {
toggle-trigger: colors;
}
/* for each color */
.colors button.grape {
toggle-trigger: colors grape;
}
.show-colors:toggle(colors grape) {
background-color: var(--grape-9);
}
</pre>
</div>
</section>
<section id="machine">
<h2>
<a href="#machine" aria-hidden="true">π</a>
State machine transitions
</h2>
<p>
This functionality & syntax is proposed
<a href="https://css.oddbird.net/toggles/explainer/#triggering-dynamic-transitions">in the explainer</a>
as syntax sugar on top of the existing functionality.
However, it's not yet clear that there are
entirely presentational (CSS-only) use-cases.
If you have ideas, we'd love to hear from you.
The following example would involve JS in production.
</p>
<p class="issue">
<a href="https://github.com/oddbird/css-toggles/issues/22">Issue 22</a>:
It is not clear in the a11y tree which 'transitions'
are currently allowed/disabled,
and the resulting generated content
is not propery announced or selectable.
</p>
<div class="request" data-testid="machine">
<button data-do="try">Try</button>
<button data-do="resolve">Resolve</button>
<button data-do="reject">Reject</button>
<button data-do="reset">Reset</button>
<div class="status" data-testid="machine-status"></div>
</div>
<pre>@machine request {
idle {
try: loading;
}
loading {
resolve: success;
reject: failure;
reset: idle;
}
failure {
try: loading;
reset: idle;
}
success {
reset: idle;
}
}
/* establish a toggle based on the machine */
.request {
toggle-root: machine(request);
}
/* the individual trigger buttons call 'transitions' */
.request button[data-do="try"] {
toggle-trigger: request do(try);
}</pre>
</section>
<footer>
<p>
Spec proposal by Tab Atkins & Miriam Suzanne.
Polyfill and demo by <a href="http://oddbird.net/">OddBird</a>.
Designed using <a href="https://open-props.style/">Open Props</a>.
</p>
</footer>
<script src="/dist/css-toggles.js" type="module"></script>
</body>
</html>