-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
776 lines (699 loc) · 19 KB
/
index.html
File metadata and controls
776 lines (699 loc) · 19 KB
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Tabbed Interface Web Component Demo</title>
<link rel="stylesheet" href="./styles.css" />
<style>
/* Component-specific demo styles */
/* Pill-style variant */
tabbed-interface.pills::part(tablist) {
gap: 8px;
margin: 0 0 1em 0;
}
tabbed-interface.pills::part(tab) {
background-color: ButtonFace;
border: none;
border-radius: 999px;
padding: 0.5em 1.5em;
}
tabbed-interface.pills::part(tab):hover {
background-color: SelectedItem;
}
tabbed-interface.pills::part(tab selected),
tabbed-interface.pills::part(tabpanel) {
background-color: Highlight;
color: HighlightText;
}
tabbed-interface.pills::part(tabpanel) {
border: none;
}
/* Minimal variant */
tabbed-interface.minimal::part(tablist) {
gap: 0;
margin: 0 0 -1px 0;
}
tabbed-interface.minimal::part(tab) {
background: transparent;
border: none;
border-radius: 0;
padding: 0.75em 1em;
}
tabbed-interface.minimal::part(tab):hover {
background: ButtonFace;
}
tabbed-interface.minimal::part(tab selected) {
background: transparent;
color: LinkText;
border-bottom: 2px solid LinkText;
}
tabbed-interface.minimal::part(tabpanel) {
padding: 1.5em 0;
border: none;
border-top: 2px solid AccentColor;
}
/* Control buttons */
.controls {
display: flex;
gap: 0.5rem;
margin-block-start: 1rem;
flex-wrap: wrap;
}
.controls button {
background: AccentColor;
color: AccentColorText;
border: none;
padding: 0.5rem 1rem;
border-radius: 4px;
font-size: 0.9rem;
cursor: pointer;
}
.controls button:hover {
opacity: 0.8;
}
.controls button:active {
opacity: 0.6;
}
/* Event output */
.output {
padding: 1em;
background: ButtonFace;
border-radius: 4px;
font-family: 'Courier New', Courier, monospace;
font-size: 0.875rem;
margin-block-start: 1rem;
border: 1px solid ButtonBorder;
}
/* Status indicator */
.status {
display: inline-block;
padding: 0.25rem 0.5rem;
background: AccentColor;
color: AccentColorText;
border-radius: 3px;
font-size: 0.875rem;
font-weight: bold;
margin-inline-start: 0.5rem;
}
</style>
</head>
<body>
<header>
<h1>Tabbed Interface Web Component</h1>
<p>
A web component that transforms heading-structured content into
an accessible tabbed interface. See the
<a
href="../"
>README</a
>
for installation and API documentation.
</p>
</header>
<main>
<!-- Basic Example -->
<section>
<h2>Basic Example</h2>
<p>
The component automatically converts headings into tabs with
accessible keyboard navigation and ARIA attributes.
</p>
<div class="demo-section">
<h3>Basic Usage</h3>
<p>
Simply wrap your heading-structured content in the
<code><tabbed-interface></code> element.
</p>
<div class="code-demo-pair">
<pre><code><mark><tabbed-interface></mark>
<h3>Getting Started</h3>
<p>First tab content.</p>
<h3>Features</h3>
<p>Second tab content.</p>
<h3>Installation</h3>
<p>Third tab content.</p>
<mark></tabbed-interface></mark></code></pre>
<div class="demo">
<tabbed-interface>
<h3>Getting Started</h3>
<p>
This is the first tab panel. The component
automatically creates tabs from headings.
</p>
<p>Headers are hidden by default in panels.</p>
<h3>Features</h3>
<ul>
<li>
Automatic tab creation from headings
</li>
<li>Full keyboard navigation support</li>
<li>ARIA attributes for accessibility</li>
<li>CSS custom properties for styling</li>
</ul>
<h3>Installation</h3>
<pre><code>npm install @aarongustafson/tabbed-interface</code></pre>
<p>Then import in your JavaScript:</p>
<pre><code>import '@aarongustafson/tabbed-interface';</code></pre>
</tabbed-interface>
</div>
</div>
</div>
</section>
<!-- Attributes -->
<section>
<h2>Attributes</h2>
<p>
The component supports several attributes to customize its
behavior.
</p>
<div class="demo-section">
<h3>Auto-Activation</h3>
<p>
Add the <code>auto-activate</code> attribute to make
tabs activate on focus. By default (without the
attribute), tabs require Enter or Space to activate,
following the manual activation pattern for better
accessibility.
</p>
<div class="code-demo-pair">
<pre><code><tabbed-interface <mark>auto-activate</mark>>
<h3>Tab One</h3>
<p>Content here.</p>
<h3>Tab Two</h3>
<p>More content.</p>
</tabbed-interface></code></pre>
<div class="demo">
<div class="note">
<strong>Try it:</strong> Use arrow keys to focus
different tabs. They activate automatically on
focus.
</div>
<tabbed-interface auto-activate>
<h3>Auto Tab 1</h3>
<p>
With auto-activation, tabs activate
immediately when you focus them with arrow
keys.
</p>
<h3>Auto Tab 2</h3>
<p>
This can be convenient for quick navigation
when you have few tabs.
</p>
<h3>Auto Tab 3</h3>
<p>
Just navigate with arrow keys and the panel
changes automatically.
</p>
</tabbed-interface>
</div>
</div>
</div>
<div class="demo-section">
<h3>Visible Headers</h3>
<p>
Use <code>show-headers</code> to keep headings visible
in tab panels.
</p>
<div class="code-demo-pair">
<pre><code><tabbed-interface <mark>show-headers</mark>>
<h3>Overview</h3>
<p>Content here.</p>
<h3>Details</h3>
<p>More content.</p>
</tabbed-interface></code></pre>
<div class="demo">
<tabbed-interface show-headers>
<h3>Overview</h3>
<p>
The heading is now visible inside the panel
along with the tab.
</p>
<h3>Details</h3>
<p>
This can be useful for certain design
patterns or when you want redundancy.
</p>
</tabbed-interface>
</div>
</div>
</div>
<div class="demo-section">
<h3>Tab List Position</h3>
<p>
Use <code>tablist-after</code> to place tabs below the
content.
</p>
<div class="code-demo-pair">
<pre><code><tabbed-interface <mark>tablist-after</mark>>
<h3>First</h3>
<p>Content appears above tabs.</p>
<h3>Second</h3>
<p>More content.</p>
</tabbed-interface></code></pre>
<div class="demo">
<tabbed-interface tablist-after>
<h3>First Section</h3>
<p>
The tabs appear below the content when using
<code>tablist-after</code>.
</p>
<h3>Second Section</h3>
<p>
This can be useful for certain layouts or
design patterns.
</p>
</tabbed-interface>
</div>
</div>
</div>
<div class="demo-section">
<h3>Default Tab</h3>
<p>
Use <code>default-tab</code> to set which tab is active
initially (by index or heading ID).
</p>
<div class="code-demo-pair">
<pre><code><tabbed-interface <mark>default-tab="1"</mark>>
<h3>Tab 0</h3>
<p>First tab.</p>
<h3>Tab 1</h3>
<p>This tab is active by default.</p>
<h3>Tab 2</h3>
<p>Third tab.</p>
</tabbed-interface></code></pre>
<div class="demo">
<tabbed-interface default-tab="1">
<h3>Tab 0</h3>
<p>First tab content.</p>
<h3>Tab 1</h3>
<p>
This tab is active by default because of
<code>default-tab="1"</code>.
</p>
<h3>Tab 2</h3>
<p>Third tab content.</p>
</tabbed-interface>
</div>
</div>
</div>
</section>
<!-- Styling Variants -->
<section>
<h2>Styling Variants</h2>
<p>
Style the component using CSS
<code>::part()</code> selectors for complete visual control.
</p>
<div class="demo-section">
<h3>Pill-Style Tabs</h3>
<p>
Create rounded pill-style tabs using
<code>::part()</code> selectors.
</p>
<div class="code-demo-pair">
<pre><code>tabbed-interface.pills::part(tablist) {
gap: 8px;
margin: 0 0 1em 0;
}
tabbed-interface.pills::part(tab) {
background-color: ButtonFace;
border: none;
border-radius: 999px;
padding: 0.5em 1.5em;
}
tabbed-interface.pills::part(tab):hover {
background-color: SelectedItem;
}
tabbed-interface.pills::part(tab selected),
tabbed-interface.pills::part(tabpanel) {
background-color: Highlight;
color: HighlightText;
}
tabbed-interface.pills::part(tabpanel) {
border: none;
}</code></pre>
<div class="demo">
<tabbed-interface class="pills" show-headers>
<h3>Tab One</h3>
<p>
The pill style is achieved entirely through
CSS <code>::part()</code> selectors.
</p>
<h3>Tab Two</h3>
<p>No JavaScript changes needed!</p>
<h3>Tab Three</h3>
<p>Fully customizable appearance.</p>
</tabbed-interface>
</div>
</div>
</div>
<div class="demo-section">
<h3>Minimal Style</h3>
<p>A clean, minimal style with an underline indicator.</p>
<div class="code-demo-pair">
<pre><code>tabbed-interface.minimal::part(tablist) {
gap: 0;
margin: 0 0 -1px 0;
}
tabbed-interface.minimal::part(tab) {
background: transparent;
border: none;
border-radius: 0;
padding: 0.75em 1em;
}
tabbed-interface.minimal::part(tab):hover {
background: ButtonFace;
}
tabbed-interface.minimal::part(tab selected) {
background: transparent;
color: LinkText;
border-bottom: 2px solid LinkText;
}
tabbed-interface.minimal::part(tabpanel) {
padding: 1.5em 0;
border: none;
border-top: 2px solid AccentColor;
}</code></pre>
<div class="demo">
<tabbed-interface class="minimal">
<h3>Design</h3>
<p>
A minimal design with just an underline for
the active tab.
</p>
<h3>Develop</h3>
<p>
Clean and simple, great for modern
interfaces.
</p>
<h3>Deploy</h3>
<p>Lightweight visual treatment.</p>
</tabbed-interface>
</div>
</div>
</div>
</section>
<!-- Advanced Features -->
<section>
<h2>Advanced Features</h2>
<p>
The component includes several advanced features for
enhanced functionality.
</p>
<div class="demo-section">
<h3>Custom Tab Titles</h3>
<p>
Use <code>data-tab-short-name</code> to show shorter
labels in tabs while keeping full headings in panels.
The full text is available as
<code>aria-label</code> for screen readers.
</p>
<div class="code-demo-pair">
<pre><code><tabbed-interface>
<h3 <mark>data-tab-short-name="Short"</mark>>
Very Long Section Title
</h3>
<p>Content here.</p>
<h3 <mark>data-tab-short-name="Emoji 🎉"</mark>>
Plain Heading
</h3>
<p>More content.</p>
</tabbed-interface></code></pre>
<div class="demo">
<tabbed-interface>
<h3 data-tab-short-name="Short">
Very Long Section Title That Wouldn't Fit
Well In a Tab
</h3>
<p>
The tab shows "Short" but the full heading
is visible in the panel and available to
screen readers.
</p>
<h3 data-tab-short-name="Emoji 🎉">
Plain Heading
</h3>
<p>
You can even add emoji or other content to
your tab titles!
</p>
<h3 data-tab-short-name="API">
API Reference Guide
</h3>
<p>Great for abbreviating long titles.</p>
</tabbed-interface>
</div>
</div>
</div>
<div class="demo-section">
<h3>Event Handling</h3>
<p>
Listen for <code>tabbed-interface:change</code> events
to respond to tab changes.
</p>
<div class="code-demo-pair">
<pre><code>document.querySelector('tabbed-interface')
.addEventListener(
<mark>'tabbed-interface:change'</mark>,
(event) => {
console.log(event.detail);
}
);</code></pre>
<div class="demo">
<tabbed-interface id="event-demo">
<h3 id="intro">Introduction</h3>
<p>
Click between tabs and watch the output
below.
</p>
<h3 id="details">Details</h3>
<p>
The event fires whenever the active tab
changes and includes useful details.
</p>
<h3 id="api">API</h3>
<p>
Event detail includes
<code>tabIndex</code>, <code>tabId</code>,
and <code>tabpanelId</code>.
</p>
</tabbed-interface>
<div id="event-output" class="output">
<strong>Waiting for tab change...</strong>
</div>
</div>
</div>
</div>
<div class="demo-section">
<h3>Programmatic Control</h3>
<p>
Control tabs programmatically using the JavaScript API.
</p>
<div class="code-demo-pair">
<pre><code>const tabs = document.querySelector(
'tabbed-interface'
);
// Navigate
tabs.<mark>next()</mark>;
tabs.<mark>previous()</mark>;
tabs.<mark>first()</mark>;
tabs.<mark>last()</mark>;
// Set active tab directly
tabs.<mark>activeIndex = 2</mark>;</code></pre>
<div class="demo">
<tabbed-interface id="programmatic-demo">
<h3>Panel A</h3>
<p>First panel content with some text.</p>
<h3>Panel B</h3>
<p>
Second panel content with more information.
</p>
<h3>Panel C</h3>
<p>
Third panel content with additional details.
</p>
<h3>Panel D</h3>
<p>
Fourth panel content to demonstrate
navigation.
</p>
</tabbed-interface>
<div class="controls">
<button
onclick="
document
.querySelector('#programmatic-demo')
.first()
"
>
First
</button>
<button
onclick="
document
.querySelector('#programmatic-demo')
.previous()
"
>
Previous
</button>
<button
onclick="
document
.querySelector('#programmatic-demo')
.next()
"
>
Next
</button>
<button
onclick="
document
.querySelector('#programmatic-demo')
.last()
"
>
Last
</button>
</div>
<div id="programmatic-output" class="output">
<strong>Current tab:</strong> 0
</div>
</div>
</div>
</div>
<div class="demo-section">
<h3>Hash Navigation</h3>
<p>
The component supports URL hash navigation for deep
linking to specific tabs.
</p>
<div class="code-demo-pair">
<pre><code><a <mark>href="#features"</mark>>
Go to Features
</a>
<tabbed-interface>
<h3 <mark>id="intro"</mark>>Introduction</h3>
<p>Content...</p>
<h3 <mark>id="features"</mark>>Features</h3>
<p>Content...</p>
</tabbed-interface></code></pre>
<div class="demo">
<p>
<a href="#hash-start">Jump to Start</a> |
<a href="#hash-middle">Jump to Middle</a> |
<a href="#hash-end">Jump to End</a>
</p>
<tabbed-interface>
<h3 id="hash-start">Start</h3>
<p>
This tab can be accessed via
<code>#hash-start</code>.
</p>
<h3 id="hash-middle">Middle</h3>
<p>
This tab can be accessed via
<code>#hash-middle</code>.
</p>
<h3 id="hash-end">End</h3>
<p>
This tab can be accessed via
<code>#hash-end</code>.
</p>
</tabbed-interface>
</div>
</div>
</div>
</section>
<!-- Accessibility -->
<section>
<h2>Accessibility</h2>
<p>
The component is built with accessibility as a core feature.
</p>
<div class="demo-section">
<h3>Keyboard Navigation</h3>
<p>
Full keyboard support following ARIA Authoring
Practices.
</p>
<div class="code-demo-pair">
<pre><code>Arrow Keys Navigate tabs
Home First tab
End Last tab
Enter/Space Activate tab and focus panel content</code></pre>
<div class="demo">
<div class="note">
<strong>Try it:</strong> Click on any tab below,
then use your keyboard to navigate.
</div>
<tabbed-interface>
<h3>Tab 1</h3>
<p>
Use Arrow keys to move between tabs. By
default, you must press Enter or Space to
activate a tab and view its content.
</p>
<h3>Tab 2</h3>
<p>
Press Home to jump to the first tab, or End
to jump to the last.
</p>
<h3>Tab 3</h3>
<p>
After activating, Enter or Space will move
focus to the first focusable element in the
panel.
</p>
</tabbed-interface>
</div>
</div>
</div>
</section>
<!-- API Reference -->
<section class="api-reference">
<h2>API Reference</h2>
<p>
For complete documentation of attributes, properties,
methods, events, CSS custom properties, keyboard navigation,
and browser support, see the
<a
href="../"
>README</a
>.
</p>
</section>
</main>
<footer>
<p>
Made with ❤️ by
<a href="https://github.com/aarongustafson">Aaron Gustafson</a>.
View the source on
<a href="https://github.com/aarongustafson/tabbed-interface"
>GitHub</a
>.
</p>
</footer>
<script src="../define.js" type="module"></script>
<script type="module">
// Event listener demo
document
.querySelector('#event-demo')
.addEventListener('tabbed-interface:change', (event) => {
const output = document.querySelector('#event-output');
output.innerHTML = `<strong>Tab changed:</strong> index=${event.detail.tabIndex}, tabId=${event.detail.tabId}, tabpanelId=${event.detail.tabpanelId}`;
});
// Programmatic control demo
document
.querySelector('#programmatic-demo')
.addEventListener('tabbed-interface:change', (event) => {
const output = document.querySelector(
'#programmatic-output',
);
output.innerHTML = `<strong>Current tab:</strong> ${event.detail.tabIndex}`;
});
</script>
</body>
</html>