Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
Last active May 24, 2022 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nolanlawson/d90390534f41770ac779efe879d9795a to your computer and use it in GitHub Desktop.
Save nolanlawson/d90390534f41770ac779efe879d9795a to your computer and use it in GitHub Desktop.
ElementInternals - ariaLabel and role
<!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