Skip to content
This repository was archived by the owner on Sep 22, 2022. It is now read-only.

Commit 1f3336d

Browse files
committed
Add a Shadow DOM example
1 parent 1c18373 commit 1f3336d

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

index.html

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,60 @@
9595
</details>
9696

9797
<button type="button" class="btn mt-4" onclick="document.querySelector('details').open = true">JS trigger: focus should return here</button>
98+
99+
<div id="shadow">
100+
</div>
101+
102+
<template id="shadow-template">
103+
<style>
104+
details {
105+
margin-top: 2em;
106+
}
107+
summary {
108+
padding: .5em;
109+
border: 1px solid;
110+
border-radius: .3em;
111+
display: inline-block;
112+
}
113+
details[open] summary:before {
114+
position: fixed;
115+
content: '';
116+
display: block;
117+
left: 0;
118+
right: 0;
119+
bottom: 0;
120+
top: 0;
121+
background: rgba(0, 0, 0, 0.3);
122+
}
123+
details-dialog {
124+
position: fixed;
125+
height: 50vh;
126+
top: 50%;
127+
margin-top: -25vh;
128+
width: 50vw;
129+
min-width: 20em;
130+
left: 50%;
131+
transform: translateX(-50%);
132+
background: #fff;
133+
border-radius: .5em;
134+
padding: 1em;
135+
}
136+
</style>
137+
<details>
138+
<summary>Dialog with Shadow DOM</summary>
139+
<details-dialog aria-label="Shadow dialog">
140+
<button type="button" data-close-dialog>Close</button>
141+
content
142+
<button type="button" data-close-dialog>Close</button>
143+
</details-dialog>
144+
</details>
145+
</template>
146+
147+
<script>
148+
const shadow = document.getElementById('shadow')
149+
const template = document.getElementById('shadow-template')
150+
const root = shadow.attachShadow({mode: 'open'})
151+
root.append(template.content.cloneNode(true))
152+
</script>
98153
</body>
99154
</html>

0 commit comments

Comments
 (0)