fix: screen reader styles, label, text updates

This commit is contained in:
Cory Dransfeldt 2024-06-19 07:49:17 -07:00
parent 435396f0fe
commit 9c394238e0
No known key found for this signature in database
5 changed files with 23 additions and 3 deletions

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "19.5.6", "version": "19.5.7",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "coryd.dev", "name": "coryd.dev",
"version": "19.5.6", "version": "19.5.7",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@cdransf/api-text": "^1.4.0", "@cdransf/api-text": "^1.4.0",

View file

@ -1,6 +1,6 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "19.5.6", "version": "19.5.7",
"description": "The source for my personal site. Built using 11ty.", "description": "The source for my personal site. Built using 11ty.",
"type": "module", "type": "module",
"scripts": { "scripts": {

View file

@ -5,6 +5,7 @@
<div class="flex-centered"> <div class="flex-centered">
<input id="menu-toggle" type="checkbox" aria-hidden="true" /> <input id="menu-toggle" type="checkbox" aria-hidden="true" />
<label class="menu-button-container" for="menu-toggle" aria-controls="primary-navigation" aria-expanded="false" tabindex="0"> <label class="menu-button-container" for="menu-toggle" aria-controls="primary-navigation" aria-expanded="false" tabindex="0">
<span id="menu-label-text" class="screen-readers-only">Toggle mobile menu</span>
<div class="menu-closed" aria-hidden="true">{% tablericon "menu" "Menu closed" %}</div> <div class="menu-closed" aria-hidden="true">{% tablericon "menu" "Menu closed" %}</div>
<div class="menu-open" aria-hidden="true">{% tablericon "x" "Menu open" %}</div> <div class="menu-open" aria-hidden="true">{% tablericon "x" "Menu open" %}</div>
</label> </label>

View file

@ -1,5 +1,6 @@
window.addEventListener('load', () => { window.addEventListener('load', () => {
const menuInput = document.getElementById('menu-toggle') const menuInput = document.getElementById('menu-toggle')
const menuLabelText = document.getElementById('menu-label-text')
const menuButtonContainer = document.querySelector('.menu-button-container') const menuButtonContainer = document.querySelector('.menu-button-container')
const menuItems = document.querySelectorAll('.menu-primary li[role="menu-item"]') const menuItems = document.querySelectorAll('.menu-primary li[role="menu-item"]')
const isMobile = () => window.innerWidth <= 768 const isMobile = () => window.innerWidth <= 768
@ -12,6 +13,14 @@ window.addEventListener('load', () => {
const link = item.querySelector('a') const link = item.querySelector('a')
if (link) link.setAttribute('tabindex', isMobile() && !isExpanded ? '-1' : '0') if (link) link.setAttribute('tabindex', isMobile() && !isExpanded ? '-1' : '0')
}) })
if(isExpanded) {
menuLabelText.textContent = 'Close mobile menu'
}
if (!isExpanded) {
menuLabelText.textContent = 'Open mobile menu'
menuButtonContainer.focus()
}
} }
updateTabIndex() updateTabIndex()

View file

@ -554,6 +554,16 @@ li {
display: none !important; display: none !important;
} }
.screen-readers-only:not(:focus):not(:active) {
clip: rect(0 0 0 0);
clip-path: inset(50%);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}
.text-centered { .text-centered {
text-align: center !important; text-align: center !important;
} }