chore: cleanup
This commit is contained in:
parent
46bcbc6617
commit
3d428bc99a
4 changed files with 2 additions and 52 deletions
|
@ -1,27 +1,12 @@
|
|||
window.addEventListener('load', () => {
|
||||
const menuInput = document.getElementById('menu-toggle')
|
||||
const menuLabelText = document.getElementById('menu-label-text')
|
||||
const menuButtonContainer = document.querySelector('.menu-button-container')
|
||||
const menuItems = document.querySelectorAll('.menu-primary li')
|
||||
const isMobile = () => window.innerWidth <= 768
|
||||
|
||||
const udpateMenuState = () => {
|
||||
const isExpanded = menuInput.checked
|
||||
menuButtonContainer.setAttribute('aria-expanded', isExpanded)
|
||||
|
||||
if(isExpanded) menuLabelText.textContent = 'Close mobile menu'
|
||||
if (!isExpanded) menuLabelText.textContent = 'Open mobile menu'
|
||||
}
|
||||
|
||||
udpateMenuState()
|
||||
|
||||
menuInput.addEventListener('change', udpateMenuState)
|
||||
|
||||
menuButtonContainer.addEventListener('keydown', e => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault()
|
||||
menuInput.checked = !menuInput.checked
|
||||
udpateMenuState()
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -35,9 +20,6 @@ window.addEventListener('load', () => {
|
|||
})
|
||||
|
||||
document.addEventListener('keydown', e => {
|
||||
if (e.key === 'Escape' && isMobile() && menuInput.checked) {
|
||||
menuInput.checked = false
|
||||
udpateMenuState()
|
||||
}
|
||||
if (e.key === 'Escape' && menuInput.checked) menuInput.checked = false
|
||||
})
|
||||
})
|
Reference in a new issue