TPAC Developer meetup, Lisbon 2016
<input type="checkbox" id="bold" checked>
<label for="bold">Bold</label>
<button id="button">
Tequila <span id="icon"></span>
</button>
<div id="content" hidden>
<p>Makes me happy!</p>
</div>
<button aria-expanded="false" id="button">
Tequila <span aria-hidden="true" id="icon"></span>
</button>
<div id="content" hidden>
<p>Makes me happy!</p>
</div>
button.addEventListener('click', disclose, false);
function disclose(event) {
if (content.hasAttribute('hidden')) {
button.setAttribute('aria-expanded', 'true');
button.setAttribute('aria-controls', 'content');
content.removeAttribute('hidden');
}
else {
button.setAttribute('aria-expanded', 'false');
content.setAttribute('hidden', 'true');
button.removeAttribute('aria-controls');
}
}
<svg version="2.0" width="300" height="200">
<rect width="75" height="50" rx="20" ry="20" />
<text x="35" y="30">Tequila!</text>
</svg>
<svg version="2.0" width="300" height="200">
<rect width="75" height="50" rx="20" ry="20"
role="button" tabindex="0" aria-expanded="false" />
<text x="35" y="30">Tequila!</text>
</svg>
button.addEventListener('click', disclose, false);
button.addEventListener('keydown', function(event) {
if (event.keyCode == 13 || event.keyCode ==32) {
disclose();
}
});