Created
April 10, 2021 23:46
-
-
Save nolanlawson/a8e6ed1da2a73f8847070a7d32a592a2 to your computer and use it in GitHub Desktop.
<video controls> in modal dialog demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Dialog element and shadow DOM example</title> | |
</head> | |
<body> | |
<button>Focusable button</button> | |
<button class="modal-button">Click to open modal dialog</button> | |
<button>Another focusable button</button> | |
<dialog> | |
<div> | |
<button>Light button</button> | |
<open-shadow></open-shadow> | |
<button>Another light button</button> | |
</div> | |
<div> | |
<button>Light button</button> | |
<closed-shadow></closed-shadow> | |
<button>Another light button</button> | |
</div> | |
<video controls src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm"></video> | |
</dialog> | |
<button>Focusable button</button> | |
<button>Focusable button</button> | |
<script> | |
class ClosedShadow extends HTMLElement { | |
constructor () { | |
super() | |
const shadow = this.attachShadow({ mode: 'closed' }) | |
shadow.innerHTML = '<button>Closed shadow button!</button>' | |
} | |
} | |
class OpenShadow extends HTMLElement { | |
constructor () { | |
super() | |
const shadow = this.attachShadow({ mode: 'open' }) | |
shadow.innerHTML = '<button>Open shadow button!</button>' | |
} | |
} | |
customElements.define('closed-shadow', ClosedShadow) | |
customElements.define('open-shadow', OpenShadow) | |
document.querySelector('.modal-button').addEventListener('click', () => { | |
const dialog = document.querySelector('dialog') | |
dialog.showModal() | |
let lastKeydown | |
dialog.addEventListener('keydown', event => { | |
lastKeydown = event | |
console.log('keydown', event) | |
}) | |
dialog.addEventListener('focusout', event => { | |
console.log('focusout', event) | |
}) | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment