Last active
May 24, 2022 20:45
-
-
Save nolanlawson/d90390534f41770ac779efe879d9795a to your computer and use it in GitHub Desktop.
ElementInternals - ariaLabel and role
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> | |
<head> | |
<title>ElementInternals with role</title> | |
<style> | |
label, fancy-label { | |
display: block; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>ElementInternals with role</h1> | |
<fancy-alert></fancy-alert> | |
<div role="alert" aria-label="I am a real alert"></div> | |
<pre id="display"></pre> | |
<script> | |
customElements.define('fancy-alert', class extends HTMLElement { | |
constructor() { | |
super() | |
this._internals = this.attachInternals() | |
display.innerHTML = ` | |
ElementInternals default value for role : ${this._internals.role} | |
ElementInternals default value for ariaLabel: ${this._internals.ariaLabel} | |
`.trim() | |
this._internals.role = 'alert' | |
this._internals.ariaLabel = 'I am a custom alert' | |
} | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment