chore: simplify logic
This commit is contained in:
parent
3cf15a323a
commit
435396f0fe
3 changed files with 9 additions and 19 deletions
4
package-lock.json
generated
4
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "coryd.dev",
|
||||
"version": "19.5.5",
|
||||
"version": "19.5.6",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "coryd.dev",
|
||||
"version": "19.5.5",
|
||||
"version": "19.5.6",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@cdransf/api-text": "^1.4.0",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "coryd.dev",
|
||||
"version": "19.5.5",
|
||||
"version": "19.5.6",
|
||||
"description": "The source for my personal site. Built using 11ty.",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
|
|
@ -3,6 +3,7 @@ window.addEventListener('load', () => {
|
|||
const menuButtonContainer = document.querySelector('.menu-button-container')
|
||||
const menuItems = document.querySelectorAll('.menu-primary li[role="menu-item"]')
|
||||
const isMobile = () => window.innerWidth <= 768
|
||||
|
||||
const updateTabIndex = () => {
|
||||
const isExpanded = menuInput.checked
|
||||
menuButtonContainer.setAttribute('aria-expanded', isExpanded)
|
||||
|
@ -12,17 +13,16 @@ window.addEventListener('load', () => {
|
|||
if (link) link.setAttribute('tabindex', isMobile() && !isExpanded ? '-1' : '0')
|
||||
})
|
||||
}
|
||||
const handleMenuChange = () => updateTabIndex()
|
||||
|
||||
updateTabIndex()
|
||||
|
||||
menuInput.addEventListener('change', handleMenuChange)
|
||||
menuInput.addEventListener('change', updateTabIndex)
|
||||
|
||||
menuButtonContainer.addEventListener('keydown', e => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault()
|
||||
menuInput.checked = !menuInput.checked
|
||||
handleMenuChange()
|
||||
updateTabIndex()
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -36,19 +36,9 @@ window.addEventListener('load', () => {
|
|||
})
|
||||
|
||||
document.addEventListener('keydown', e => {
|
||||
if (e.key === 'Escape') {
|
||||
if (isMobile() && menuInput.checked) {
|
||||
if (e.key === 'Escape' && isMobile() && menuInput.checked) {
|
||||
menuInput.checked = false
|
||||
handleMenuChange()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
window.addEventListener('resize', () => {
|
||||
updateTabIndex()
|
||||
if (!isMobile() && menuInput.checked) {
|
||||
menuInput.checked = false
|
||||
handleMenuChange()
|
||||
}
|
||||
})
|
||||
})
|
Reference in a new issue