generated from oddbird/polyfill-template
-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.html
772 lines (740 loc) · 30.5 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
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
<!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>Popover Attribute Polyfill</title>
<link
href="https://use.typekit.net/af/442215/000000000000000000010b5a/27/l?primer=7ceb210e49ade74e23101e10f006f110a0b6588c7c57777a6e3d98a38b749696&fvd=n4&v=3"
as="font"
type="font/woff2"
crossorigin
/>
<style>
@layer reset, initial, popover-polyfill, default, demo;
@import url('/css/reset.css') layer(reset);
@import url('/css/demo.css') layer(demo);
@import url('/css/prism.css') layer(initial);
@import url('/css/fonts.css') layer(initial);
@import url('/css/base.css') layer(default);
@import url('/css/props.css') layer(initial);
@import url('/css/code.css') layer(default);
</style>
<style>
@layer popover-polyfill;
@layer consumer {
[data-popover~='layered-styles'] {
background-color: #d00d1e;
}
}
</style>
<script type="module">
import { apply, isSupported } from './dist/popover-fn.js';
const note = document.getElementById('browser-support');
if (isSupported()) {
console.log('native `popover` support detected, no polyfill used');
note.innerText =
'This browser supports the Popover API natively, so the polyfill has not been applied.';
} else {
apply();
console.log('polyfill applied');
note.innerText =
'This browser does not support the Popover API natively, so the polyfill has been applied.';
}
</script>
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<script src="https://unpkg.com/[email protected]/components/prism-core.min.js"></script>
<script src="https://unpkg.com/[email protected]/plugins/autoloader/prism-autoloader.min.js"></script>
<!-- TypeKit Fonts -->
<script src="https://use.typekit.net/slx1xnq.js"></script>
<script>
try {
Typekit.load({ async: true });
} catch (e) {}
</script>
</head>
<body>
<header class="site-header">
<a href="https://www.oddbird.net/" rel="home" id="banner-logo">
<svg
data-logo="oddbird"
xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
focusable="false"
width="200px"
height="96px"
viewBox="0 0 181.6 86.7"
id="oddbird-logo"
>
<path
class="wordmark"
d="M90.7 4.5c1.3.2 1.5.4 1.5.7v11.7c1.8.5 3.5 1.2 5.3 2.1v-3.2H99c3.8 0 6.6 1.7 6.6 5.4 0 1.1-.3 2-.8 2.8.9.8 1.8 1.6 2.7 2.5 2.6-1.1 3.8-3 3.8-5.4 0-3.5-2.9-5.8-7.7-6.3v-.2c3.7-.6 6.8-2.8 6.8-6.2s-2.8-5.6-9.9-5.6H89.3l.1 1.6 1.3.1zm6.8-.1h1.7c3.7 0 5.5 2 5.5 5 0 2.6-1.8 4.6-5 4.7h-2.2V4.4zM116 26l-1.8.2-.1 1.6h3.3c1.7-2.3 3.4-4.4 5.3-5.1V5.2c0-.4.3-.6 1.4-.8l1.9-.2.1-1.6h-12l.1 1.6 1.7.2c1.3.2 1.5.4 1.5.7v20c0 .5-.4.7-1.4.9zM15.3 2.2C7.9 2.2 1.7 7.8 1.7 15.5s5.4 12.9 13.4 12.9c7.4 0 13.6-5.6 13.6-13.3S23.3 2.2 15.3 2.2zm0 24.3c-4.3 0-7.8-4.1-7.8-11.5 0-7.2 3.4-11 7.6-11 4.3 0 7.8 4.1 7.8 11.5 0 7.3-3.4 11-7.6 11zM164.8 2.6l-10.5.2.1 1.6 1.3.2c1.3.2 1.5.4 1.5.7v20c0 .4-.4.6-1.4.8l-1.4.2-.1 1.6h10.5c9.7 0 15.1-6.2 15.1-13.1-.1-7.2-5.9-12.4-15.1-12.2zm.6 23.5l-2.9-.6V4.4h1.3c6.9 0 10.3 4.5 10.3 11.2 0 5.8-3.2 10.4-8.7 10.5zM130.3 4.5c1.3.2 1.5.4 1.5.7v17.7c1.8.5 3.6 1.1 5.3 1.7v-7.7h2.4l4.2 7.7 1.6 3.2h7.7l-.1-1.6-1.1-.2c-.8-.2-1.3-.6-2.2-1.8l-5.2-8.2c3.6-1.3 5.7-3.7 5.7-6.9 0-3.7-3.1-6.2-9.6-6.2h-11.7l.1 1.6h1.4zm6.8 0h1.9c3.4-.1 5.5 1.8 5.5 5.4 0 3.4-2 5.1-4.9 5.4l-2.4-.2V4.5h-.1zM33.4 26l-1.4.1-.1 1.6h5.4c1.2-.8 2.4-1.5 3.6-2.1l-.8-.2v-21h1.3c6.9 0 10.3 4.5 10.3 11.2 0 2.3-.5 4.3-1.4 6 .8-.2 1.7-.3 2.5-.3.9 0 1.7.1 2.5.4 1.4-2.1 2.1-4.5 2.1-7.1 0-7-5.8-12.2-15-12.1l-10.5.2.1 1.6 1.3.2c1.3.2 1.5.4 1.5.7v20c0 .4-.4.6-1.4.8zM62 4.5c1.3.2 1.5.4 1.5.7v20c0 .4-.4.6-1.4.8l-1.3.1c.5.5.9 1.1 1.3 1.6h7.6c.4-.6.7-1.2 1.1-1.8l-2-.4V4.4h1.3c6.9 0 10.3 4.5 10.3 11.2 0 .6 0 1.1-.1 1.7.6-.3 1.3-.5 1.9-.7 1.2-.3 2.5-.5 3.9-.5 0-.5.1-.9.1-1.4 0-7-5.8-12.2-15-12.1l-10.6.1.1 1.6 1.3.2z"
/>
<path
class="logomark"
d="M143.1 28.7c-3.8-1.7-14.6-6.6-19.6-4.9-3.4 1.1-7.3 9.4-9.9 11.8-.3.2-.6.5-1 .8-7.1-13.4-20.8-21-29.9-18.5-6.2 1.7-11.9 8.9-14.5 18.1-4.5-2.7-6.8-7.2-10.8-11.3-3.1-3.2-7.3-1.9-10.9-.2-7.2 3.3-16.6 8.2-16.3 15.9 4.2-3 8.3-2.1 9.6 3.4.3 1 2.6-3.6 5.4-4.6 3.2-1.2 6.7 1.7 7.4 4.9.2.6 2.9-3.5 5.7-2.1 2 .9 3.2 5.1 3.9 4.7 2-1.3 3.4-2.8 4.8-4-.5 4.7-.2 9.7 1.2 14.7.1.3.2.6.2.8 1-8.9 5.9-16.2 11.4-17.7 7.7-2.2 20.1 5.8 23.8 18.9 2.7 9.7.8 19.3-4.2 24.6.6-.1 1.2-.2 1.8-.4 13.1-3.7 19.6-21.4 14.5-39.5-.1-.4-.2-.7-.3-1 3.2 1.7 4.7 4.5 4.8 4.1 1.2-5.6 7.9-5.7 12.3-1.7.4.4.6-4.3 2.3-4.9 2.7-1 5.7.5 8.5 2.2.5.3.4-2.2.3-2.5-.2-1.2-.1-2.5 1.3-2.9 2.1-.6 4.5.5 6.4.9-.5-4.5-4.6-8-8.2-9.6z"
/>
</svg>
</a>
<nav data-nav>
<ul data-navlist>
<li>
<a
data-nav
href="https://html.spec.whatwg.org/multipage/popover.html"
target="_blank"
rel="noopener noreferrer"
>Spec</a
>
</li>
<li>
<a
data-nav
href="https://developer.mozilla.org/en-US/docs/Web/API/Popover_API"
target="_blank"
rel="noopener noreferrer"
>API</a
>
</li>
<li>
<a
data-nav
href="https://github.com/oddbird/popover-polyfill"
target="_blank"
rel="noopener noreferrer"
>Source</a
>
</li>
</ul>
</nav>
</header>
<main>
<header class="main-header">
<h1 id="title">
<span class="subtitle">Polyfill Demo</span>
<span data-popover-title>Popover</span>
<span data-popover-title="attribute">Attribute</span>
</h1>
<div class="description">
<p>
OddBird’s Popover Attribute Polyfill – built in collaboration with
<a
href="https://github.com/keithamus"
target="_blank"
rel="noopener noreferrer"
>Keith Cirkel</a
>
and used in production by GitHub – lets developers preview the
upcoming mechanism for
<a
href="https://open-ui.org/components/popover.research.explainer/"
target="_blank"
rel="noopener noreferrer"
>displaying popover content</a
>
on top of other page content, drawing the user’s attention to
specific important information or actions that need to be taken.
</p>
<p>
This polyfills the HTML <code>popover</code> attribute and
<code>showPopover</code>, <code>hidePopover</code>, and
<code>togglePopover</code> methods on <code>HTMLElement</code>, as
well as the <code>popovertarget</code> and
<code>popovertargetaction</code> attributes on
<code><button></code> elements.
</p>
</div>
</header>
<div data-alert>
<p>
<span id="browser-support"></span>
See which browsers have
<a
href="https://caniuse.com/?search=popover"
target="_blank"
rel="noopener noreferrer"
>native Popover API support</a
>.
</p>
</div>
<div id="popovers">
<div id="defaultPopover" data-popover popover>Default Popover</div>
<div id="manualPopover" data-popover="manual" popover="manual">
Manual Popover
</div>
<div id="emptyStatePopover" data-popover popover="">
Empty State Popover
</div>
<dialog id="dialogPopover" data-popover popover>Dialog Popover</dialog>
<div id="showHidePopover" data-popover="manual" popover="manual">
Popover with Explicit Action. This popover has an
<a href="#" autofocus>autofocus link.</a>
</div>
<div id="singleActionShowPopover" data-popover popover>
Single Action Popover. This popover has an
<a href="#" autofocus>autofocus link.</a>
</div>
<div id="crossTreeHost"></div>
<div id="menuPopover" data-popover="nested" popover>
<ul class="menu-list">
<li><button data-btn="menu-item">Item 1</button></li>
<li><button data-btn="menu-item">Item 2</button></li>
<li>
<button
popovertarget="nestedPopover"
popovertargetaction="show"
data-btn="menu-item"
>
Show Sub Menu
</button>
</li>
</ul>
<div
id="nestedPopover"
data-popover="nested"
popover
style="left: 200px"
>
<ul class="menu-list">
<li>
<button data-btn="menu-item">Submenu Item 1</button>
</li>
<li>
<button data-btn="menu-item">Submenu Item 2</button>
</li>
<li>
<button data-btn="menu-item">Submenu Item 3</button>
</li>
</ul>
</div>
</div>
<div id="shadowInvokedPopover" data-popover popover>
Shadow Invoked Popover
</div>
<div id="shadowNestedPopover" data-popover popover>
Menu with Shadowed Popover:
<div id="menuHost"></div>
</div>
<div id="layeredStylesPopover" data-popover="layered-styles" popover>
Popover with Layered Styles (should be red if browser has
<code>@layer</code> support)
</div>
<div id="test-popover-invalid" popover="invalid">
Invalid Popover ("invalid")
</div>
<div id="test-popover-invalid-hint" popover="hint">
Invalid Popover ("hint")
</div>
<div id="test-popover" popover="auto">Test Popover 1 (auto)</div>
<div id="test-popover-2" popover="auto">Test Popover 2 (auto)</div>
</div>
<div id="buttons" class="demo-section">
<section id="popover-default" class="demo-item">
<h2 data-header>
<a href="#popover-default" aria-hidden="true">🔗</a>
Default Popover
</h2>
<p class="note">
Popovers take a state of “auto” or “manual”. If no state is
provided, the popover takes on the behavior of its default state,
which is “auto”. Auto popovers can be “light dismissed” by selecting
anywhere on the page, clicking the popover control button, or
opening another popover on the page.
</p>
<button popovertarget="defaultPopover" aria-expanded="false" data-btn>
<span>Toggle Default Popover</span>
</button>
<pre><code class="language-html"
><button popovertarget="defaultPopover" aria-expanded="false">
Toggle Default Popover
</button>
<div id="defaultPopover" popover>Default Popover</div></code></pre>
</section>
<section id="popover-manual" class="demo-item">
<h2 data-header>
<a href="#popover-manual" aria-hidden="true">🔗</a>
Manual Popover
</h2>
<button popovertarget="manualPopover" data-btn>
Toggle Manual Popover
</button>
<p class="note">
Manual popovers must be dismissed by toggling the control button or
clicking another control that is explicity set to hide the popover.
</p>
<pre><code class="language-html"
><button popovertarget="manualPopover">
Toggle Manual Popover
</button>
<div id="manualPopover" popover="manual">Manual Popover</div></code></pre>
</section>
<section id="popover-dialog" class="demo-item">
<h2 data-header>
<a href="#popover-dialog" aria-hidden="true">🔗</a>
Dialog Popover
</h2>
<button popovertarget="dialogPopover" data-btn>
Toggle Dialog Popover
</button>
<p class="note">
<code><dialog></code> elements can also be used as popovers.
</p>
<pre><code class="language-html"
><button popovertarget="dialogPopover">
Toggle Dialog Popover
</button>
<dialog id="dialogPopover" popover>Dialog Popover</dialog></code></pre>
</section>
<section id="popover-empty-state" class="demo-item">
<h2 data-header>
<a href="#popover-empty-state" aria-hidden="true">🔗</a>
Popover with Empty State
</h2>
<p class="note">
A popover with an empty state behaves as if it were set to “auto”.
</p>
<button popovertarget="emptyStatePopover" data-btn>
Toggle Empty State Popover
</button>
<pre><code class="language-html"
><button popovertarget="emptyStatePopover">Toggle Empty State Popover</button>
<div id="emptyStatePopover" popover="">Empty State Popover</div></code></pre>
</section>
<section id="popover-explicit-actions" class="demo-item">
<h2 data-header>
<a href="#popover-explicit-actions" aria-hidden="true">🔗</a>
Popover Controls with Explicit Actions
</h2>
<p class="note">
Popover button controls can be set to “show” or “hide” with the
<code>popovertargetaction</code> attribute. This
<code>popover</code> also has a link with an
<code>autofocus</code> attribute, which receives focus when the
popover is opened.
</p>
<div class="button-group">
<button
popovertargetaction="show"
popovertarget="showHidePopover"
data-btn
>
Show Popover with Explicit Action
</button>
<button
popovertargetaction="hide"
popovertarget="showHidePopover"
data-btn
>
Hide Popover with Explicit Action
</button>
</div>
<pre><code class="language-html"
><button popovertargetaction="show" popovertarget="showHidePopover">
Show Popover with Explicit Action
</button>
<button popovertargetaction="hide" popovertarget="showHidePopover">
Hide Popover with Explicit Action
</button>
<div id="showHidePopover" popover="manual">
Popover with Explicit Action. This popover has an <a href="#" autofocus>autofocus link.</a>
</div></code></pre>
</section>
<section id="popover-show-action" class="demo-item">
<h2 data-header>
<a href="#popover-show-action" aria-hidden="true">🔗</a>
Popover Control with Only the “Show” Action
</h2>
<p class="note">
Since the value of the <code>popovertargetaction</code> attribute is
set to “show”, clicking the button will only open the popover. The
popover can be closed by selecting elsewhere on the page, or opening
another popover. This <code>popover</code> also has a link with an
<code>autofocus</code> attribute, which receives focus when the
popover is opened.
</p>
<button
popovertargetaction="show"
popovertarget="singleActionShowPopover"
data-btn
>
Show Single Action Popover
</button>
<pre><code class="language-html"
><button popovertargetaction="show" popovertarget="singleActionShowPopover">
Show Single Action Popover
</button>
<div id="singleActionShowPopover" popover>
Single Action Popover. This popover has an <a href="#" autofocus>autofocus link.</a>
</div></code></pre>
</section>
<section id="popover-invalid-target" class="demo-item">
<h2 data-header>
<a href="#popover-invalid-target" aria-hidden="true">🔗</a>
Popover Control with Invalid Target
</h2>
<p class="note">
Since no popover matches the
<code>popovertarget</code> of “invalidTargetPopover”, no popover
will open.
</p>
<button popovertarget="invalidTargetPopover" data-btn>
Toggle nothing
</button>
<pre><code class="language-html"
><button popovertarget="invalidTargetPopover">
Toggle Nothing
</button></code></pre>
</section>
<section id="popover-cross-tree" class="demo-item">
<h2 data-header>
<a href="#popover-cross-tree" aria-hidden="true">🔗</a>
Targeting Elements in a Different Tree Scope
</h2>
<p class="note">
This button created in the light DOM has its
<code>popovertarget</code>, which is in the shadow DOM, set using
JavaScript.
<br />
<br />
<em
>Note that while this use-case is supported by the polyfill,
native browser support has
<a
href="https://github.com/whatwg/html/issues/9109"
target="_blank"
rel="noopener noreferrer"
>lagged behind</a
>.</em
>
</p>
<button id="crossTreeToggle" data-btn>
Toggle Cross Tree Popover
</button>
<script type="module">
const crossTreeHost = document.getElementById('crossTreeHost');
const crossTreeShadowRoot = crossTreeHost.attachShadow({
mode: 'open',
});
crossTreeShadowRoot.innerHTML = `
<style>
@layer reset, initial, popover-polyfill, default, demo;
@import url('/css/demo.css') layer(demo);
@import url('/css/fonts.css') layer(initial);
@import url('/css/base.css') layer(default);
</style>
<div id="crossTreePopover" popover data-popover>Shadowed Popover</div>`;
document.getElementById('crossTreeToggle').popoverTargetElement =
crossTreeShadowRoot.getElementById('crossTreePopover');
</script>
<pre><code class="language-html"
><!-- Light DOM -->
<button id="crossTreeToggle">
Toggle Cross Tree Popover
</button>
<div id="crossTreeHost">
<!-- Shadow DOM -->
<div id="crossTreePopover" popover>Shadowed Popover</div>
</div></code>
<code class="language-js"
>// JavaScript
const crossTreeHost = document.getElementById('crossTreeHost');
const crossTreeShadowRoot = crossTreeHost.attachShadow({ mode: 'open' });
crossTreeShadowRoot.innerHTML = '<div id="crossTreePopover" popover>Shadowed Popover</div>';
document.getElementById('crossTreeToggle').popoverTargetElement = crossTreeShadowRoot.getElementById('crossTreePopover');</code></pre>
</section>
<section id="popover-nested" class="demo-item">
<h2 data-header>
<a href="#popover-nested" aria-hidden="true">🔗</a>
Nested Popovers
</h2>
<p class="note">Popovers can be nested within other popovers.</p>
<button
popovertargetaction="show"
popovertarget="menuPopover"
data-btn
>
Show Menu
</button>
<pre><code class="language-html"
><button popovertargetaction="show" popovertarget="menuPopover">
Show Menu
</button>
<div id="menuPopover" popover>
<ul>
<li><button>Item 1</button></li>
<li><button>Item 2</button></li>
<li>
<button popovertarget="nestedPopover" popovertargetaction="show">
Show Sub Menu
</button>
</li>
</ul>
<div id="nestedPopover" popover style="left: 200px">
<ul>
<li><button>Submenu Item 1</button></li>
<li><button>Submenu Item 2</button></li>
<li><button>Submenu Item 3</button></li>
</ul>
</div>
</div></code></pre>
</section>
<section id="popover-shadow-invoked" class="demo-item">
<h2 data-header>
<a href="#popover-shadow-invoked" aria-hidden="true">🔗</a>
Opening a Popover with an Element Created in the Shadow Root
</h2>
<p class="note">
Elements created in the shadow DOM can trigger a popover.
</p>
<button popovertarget="shadowInvokedPopover" data-btn>
<span id="shadowInvokedHost"></span>
</button>
<script type="module">
const shadowInvokedHost =
document.getElementById('shadowInvokedHost');
const shadowRoot = shadowInvokedHost.attachShadow({ mode: 'open' });
shadowRoot.innerHTML = `<span>Toggle Shadow Invoked Popover</span>`;
</script>
<pre><code class="language-html"
><!-- Light DOM -->
<button popovertarget="shadowInvokedPopover">
<span id="shadowInvokedHost">
<!-- Shadow DOM -->
<span>Toggle Shadow Invoked Popover</span>
</span>
</button>
<div id="shadowInvokedPopover" popover>
Shadow Invoked Popover
</div></code>
<code class="language-js"
>// JavaScript
const shadowInvokedHost = document.getElementById('shadowInvokedHost');
const shadowRoot = shadowInvokedHost.attachShadow({ mode: 'open' });
shadowRoot.innerHTML = `<span>Toggle Shadow Invoked Popover</span>`;</code></pre>
</section>
<section id="popover-shadow-nested" class="demo-item">
<h2 data-header>
<a href="#popover-shadow-nested" aria-hidden="true">🔗</a>
Nested Popovers in Shadow DOM
</h2>
<p class="note">
Popovers can be nested within other popovers in the shadow DOM.
</p>
<button popovertarget="shadowNestedPopover" data-btn>
Toggle Menu with Shadowed Popover
</button>
<script type="module">
const menuHost = document.getElementById('menuHost');
const menuShadowRoot = menuHost.attachShadow({ mode: 'open' });
menuShadowRoot.innerHTML = `
<style>
@layer reset, initial, popover-polyfill, default, demo;
@import url('/css/demo.css') layer(demo);
@import url('/css/fonts.css') layer(initial);
@import url('/css/base.css') layer(default);
</style>
<button popovertarget="shadowedMenuInner" data-btn>
Toggle Inner Shadowed Popover
</button>
<div id="shadowedMenuInner" data-popover="inner-shadowed" popover>
Inner Shadowed Popover
</div>`;
</script>
<pre><code class="language-html"
><!-- Light DOM -->
<button popovertarget="shadowNestedPopover">
Toggle Menu with Shadowed Popover
</button>
<div id="shadowNestedPopover" popover>
Menu with Shadowed Popover:
<div id="menuHost">
<!-- Shadow DOM -->
<button popovertarget="shadowedMenuInner">
Toggle Inner Shadowed Popover
</button>
<div id="shadowedMenuInner" popover>
Inner Shadowed Popover
</div>
</div>
</div></code>
<code class="language-js"
>// JavaScript
const menuHost = document.getElementById('menuHost');
const menuShadowRoot = menuHost.attachShadow({ mode: 'open' });
menuShadowRoot.innerHTML = `
<button popovertarget="shadowedMenuInner">
Toggle Inner Shadowed Popover
</button>
<div id="shadowedMenuInner" popover>
Inner Shadowed Popover
</div>`;</code></pre>
</section>
<section id="popover-layered-styles" class="demo-item">
<h2 data-header>
<a href="#popover-layered-styles" aria-hidden="true">🔗</a>
Layers Support
</h2>
<p class="note">
When supported, the polyfill creates a cascade layer named
<code>popover-polyfill</code>. If author styles are not in layers
then this should have no impact. If layers are used, authors will
need to ensure the polyfill layer is declared first (e.g.
<code>@layer popover-polyfill, other, layers;</code>).
</p>
<button popovertarget="layeredStylesPopover" data-btn>
Toggle Popover with Layered Styles
</button>
<pre><code class="language-html"
><button popovertarget="layeredStylesPopover">
Toggle Popover with Layered Styles
</button>
<div id="layeredStylesPopover" data-popover="layered-styles" popover>
Popover with Layered Styles
(should be red if browser has <code>@layer</code> support)
</div></code>
<code class="language-css"
>/* CSS */
@layer popover-polyfill;
@layer consumer {
[data-popover~='layered-styles'] {
background-color: #d00d1e;
}
}</code></pre>
</section>
<section id="popover-shadow-root" class="demo-item">
<h2 data-header>
<a href="#popover-shadow-root" aria-hidden="true">🔗</a>
Popovers and Controls Created Fully in the Shadow Root
</h2>
<p class="note">
Here, both the popover control button and the popover are created in
the Shadow DOM.
</p>
<div id="fullShadowHost"></div>
<script type="module">
const fullShadowHost = document.getElementById('fullShadowHost');
const fullShadowRoot = fullShadowHost.attachShadow({
mode: 'open',
});
fullShadowRoot.innerHTML = `
<style>
@layer reset, initial, popover-polyfill, default, demo;
@import url('/css/demo.css') layer(demo);
@import url('/css/fonts.css') layer(initial);
@import url('/css/base.css') layer(default);
</style>
<div id="shadowedPopover" popover data-popover>Shadowed Popover</div>
<div>
<div id="shadowedNestedPopover" popover data-popover>Shadowed Nested Popover</div>
</div>
<div class="button-group">
<button popovertarget="shadowedPopover" data-btn>
Toggle Shadowed Popover
</button>
<button popovertarget="shadowedNestedPopover" data-btn>
Toggle Shadowed Nested Popover
</button>
</div>`;
</script>
<pre><code class="language-html"
><!-- Shadow DOM -->
<button popovertarget="shadowedPopover">
Toggle Shadowed Popover
</button>
<button popovertarget="shadowedNestedPopover">
Toggle Shadowed Nested Popover
</button>
<div id="shadowedPopover" popover>Shadowed Popover</div>
<div>
<div id="shadowedNestedPopover" popover>Shadowed Nested Popover</div>
</div></code></pre>
</section>
<section id="popover-shadow-root-with-slot" class="demo-item">
<h2 data-header>
<a href="#popover-shadow-root-with-slot" aria-hidden="true">🔗</a>
Shadow Root Popover with Slotted Contents
</h2>
<p class="note">
Here, both the popover control button and the popover are created in
the Shadow DOM, but an element is slotted in the popover.
</p>
<div id="shadowHostWithSlot">
<div><span>I’m a slotted element</span></div>
</div>
<script type="module">
const shadowHostWithSlot =
document.getElementById('shadowHostWithSlot');
const shadowHostWithSlotRoot = shadowHostWithSlot.attachShadow({
mode: 'open',
});
shadowHostWithSlotRoot.innerHTML = `
<style>
@layer reset, initial, popover-polyfill, default, demo;
@import url('/css/demo.css') layer(demo);
@import url('/css/fonts.css') layer(initial);
@import url('/css/base.css') layer(default);
</style>
<div id="shadowedPopoverWithSlot" popover data-popover><slot></slot></div>
<div class="button-group">
<button popovertarget="shadowedPopoverWithSlot" data-btn>
Toggle Shadowed Popover
</button>
</div>`;
</script>
<pre><code class="language-html"
><!-- Light DOM -->
<div id="shadowHostWithSlot">
<div><span>I’m a slotted element</span></div>
</div>
<!-- Shadow DOM -->
<button popovertarget="shadowedPopoverWithSlot">
Toggle Shadowed Popover
</button>
<div id="shadowedPopoverWithSlot" popover>
<slot></slot>
</div></code></pre>
</section>
<section id="sponsor" class="demo-item">
<h2>Sponsor OddBird’s OSS Work</h2>
<p>
At OddBird, we love contributing to the languages & tools developers
rely on. We’re currently working on polyfills for new Popover &
Anchor Positioning functionality, as well as CSS specifications for
functions, mixins, and responsive typography. Help us keep this work
sustainable and centered on your needs as a developer! We display
sponsor logos and avatars on our
<a
href="https://www.oddbird.net/polyfill/#open-source-sponsors"
target="_blank"
rel="noopener noreferrer"
>website</a
>.
</p>
<a
href="https://github.com/sponsors/oddbird"
target="_blank"
rel="noopener noreferrer"
>Sponsor OddBird’s OSS Work</a
>
</section>
</div>
</main>
<footer class="site-footer">
Polyfill by
<a
href="https://www.oddbird.net/"
target="_blank"
rel="noopener noreferrer"
>OddBird</a
>
in collaboration with
<a
href="https://github.com/keithamus"
target="_blank"
rel="noopener noreferrer"
>Keith Cirkel</a
>.
</footer>
</body>
</html>