Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
Created March 10, 2022 23:35
Show Gist options
  • Save nolanlawson/e20b300ba6be925bf8e707321f9417cd to your computer and use it in GitHub Desktop.
Save nolanlawson/e20b300ba6be925bf8e707321f9417cd to your computer and use it in GitHub Desktop.
Test ariaInvalid
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test ariaInvalid</title>
</head>
<body>
<h1>Test ariaInvalid</h1>
<input id="input1" type="text">
<input id="input2" type="text">
<pre></pre>
<script type="module">
const input1 = document.querySelector('#input1')
const input2 = document.querySelector('#input2')
const pre = document.querySelector('pre')
input1.ariaInvalid = 'true'
input2.setAttribute('aria-invalid', "true")
const stringify = _ => typeof _ === 'undefined' ? 'undefined' : JSON.stringify(_)
const reflectedAttr = input1.getAttribute('aria-invalid')
const reflectedProp = input2.ariaInvalid
pre.innerHTML = `
Reflect ariaInvalid prop to aria-invalid attr
input1.getAttribute('aria-invalid') === ${stringify(reflectedAttr)} ${reflectedAttr === 'true' ? '✅' : '❌'}
Reflect aria-invalid attr to ariaInvalid prop
input2.ariaInvalid === ${stringify(reflectedProp)} ${reflectedProp === 'true' ? '✅' : '❌'}
`
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment