-
Notifications
You must be signed in to change notification settings - Fork 5
/
web-components.html
86 lines (78 loc) · 2.75 KB
/
web-components.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>focus-within-polyfill - Web Components Demo</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css">
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>Web Components :focus-within test</h1>
<p>
This page contains various web components and demonstrates a proposal for only drawing a focus
ring when the keyboard is being used. Navigate through the interactive elements in various
ways (using mouse, switch to keyboard, try it on a touch device). You should see a focus
indicator on the element's parents whether you interact with them via keyboard or mouse.
</p>
</header>
<main>
<section class="web-components">
<h2>
Web Components
<span>:focus-within</span>
</h2>
<outer-custom-element></outer-custom-element>
<inner-custom-element></inner-custom-element>
</section>
</main>
<script src="https://unpkg.com/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
<script src="https://unpkg.com/focus-within-polyfill"></script>
<script>
(function() {
const tagName = 'outer-custom-element';
const template = document.createElement('template');
template.innerHTML = `
<div id="outer-custom-element">
<h3>Outer Custom Element</h3>
<a href="#">Outer Focusable link</a>
</div>
`;
class OpenShadow extends HTMLElement {
connectedCallback() {
if (!this.shadowRoot) {
this.attachShadow({mode: 'open'});
this.shadowRoot.appendChild(template.content.cloneNode(true));
}
}
}
const register = () => customElements.define(tagName, OpenShadow);
window.WebComponents ? window.WebComponents.waitFor(register) : register();
})()
</script>
<script>
(function() {
const tagName = 'inner-custom-element';
const template = document.createElement('template');
template.innerHTML = `
<div id="inner-custom-element">
<h3>Inner Custom Element</h3>
<a href="#">Inner Focusable link</a>
</div>
`;
class CloseShadow extends HTMLElement {
connectedCallback() {
if (!this.shadowRoot) {
this.attachShadow({mode: 'open'});
this.shadowRoot.appendChild(template.content.cloneNode(true));
}
}
}
const register = () => customElements.define(tagName, CloseShadow);
window.WebComponents ? window.WebComponents.waitFor(register) : register();
})();
</script>
</body>
</html>