chore: nesting + index behavior

This commit is contained in:
Cory Dransfeldt 2024-06-19 09:20:28 -07:00
parent 881ed4d874
commit 897ef64d3c
No known key found for this signature in database
4 changed files with 27 additions and 28 deletions

10
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "coryd.dev",
"version": "19.5.7",
"version": "19.5.9",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "coryd.dev",
"version": "19.5.7",
"version": "19.5.9",
"license": "MIT",
"dependencies": {
"@cdransf/api-text": "^1.4.0",
@ -532,9 +532,9 @@
"peer": true
},
"node_modules/@types/node": {
"version": "20.14.5",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.5.tgz",
"integrity": "sha512-aoRR+fJkZT2l0aGOJhuA8frnCSoNX6W7U2mpNq63+BxBIj5BQFt8rHy627kijCmm63ijdSdwvGgpUsU6MBsZZA==",
"version": "20.14.6",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.6.tgz",
"integrity": "sha512-JbA0XIJPL1IiNnU7PFxDXyfAwcwVVrOoqyzzyQTyMeVhBzkJVMSkC1LlVsRQ2lpqiY4n6Bb9oCS6lzDKVQxbZw==",
"dev": true,
"license": "MIT",
"dependencies": {

View file

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

View file

@ -5,28 +5,23 @@ window.addEventListener('load', () => {
const menuItems = document.querySelectorAll('.menu-primary li[role="menu-item"]')
const isMobile = () => window.innerWidth <= 768
const updateTabIndex = () => {
const udpateMenuState = () => {
const isExpanded = menuInput.checked
menuButtonContainer.setAttribute('aria-expanded', isExpanded)
menuItems.forEach(item => {
const link = item.querySelector('a')
if (link) link.setAttribute('tabindex', isMobile() && !isExpanded ? '-1' : '0')
})
if(isExpanded) menuLabelText.textContent = 'Close mobile menu'
if (!isExpanded) menuLabelText.textContent = 'Open mobile menu'
}
updateTabIndex()
udpateMenuState()
menuInput.addEventListener('change', updateTabIndex)
menuInput.addEventListener('change', udpateMenuState)
menuButtonContainer.addEventListener('keydown', e => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault()
menuInput.checked = !menuInput.checked
updateTabIndex()
udpateMenuState()
}
})
@ -42,7 +37,7 @@ window.addEventListener('load', () => {
document.addEventListener('keydown', e => {
if (e.key === 'Escape' && isMobile() && menuInput.checked) {
menuInput.checked = false
updateTabIndex()
udpateMenuState()
}
})
})

View file

@ -51,22 +51,26 @@
#menu-toggle {
display: none;
}
#menu-toggle:checked + .menu-button-container .menu-closed {
display: none;
}
&:checked + .menu-button-container {
& .menu-closed {
display: none;
}
#menu-toggle:checked + .menu-button-container .menu-open {
display: block;
}
& .menu-open {
display: block;
}
}
#menu-toggle:not(:checked) + .menu-button-container .menu-closed {
display: block;
}
&:not(:checked) + .menu-button-container {
& .menu-closed {
display: block;
}
#menu-toggle:not(:checked) + .menu-button-container .menu-open {
display: none;
& .menu-open {
display: none;
}
}
}
a[role="menu-item"]:focus {