feat: modal enhancements

This commit is contained in:
Cory Dransfeldt 2024-09-18 10:55:56 -07:00
parent 870c40cb46
commit 54cc4bdc01
No known key found for this signature in database
4 changed files with 36 additions and 10 deletions

4
package-lock.json generated
View file

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

View file

@ -1,6 +1,6 @@
{
"name": "coryd.dev",
"version": "24.16.5",
"version": "24.17.0",
"description": "The source for my personal site. Built using 11ty (and other tools).",
"type": "module",
"scripts": {

View file

@ -26,19 +26,45 @@ window.addEventListener('load', () => {
})
})()
// modal keyboard controls
// modal keyboard controls and scroll management
;(() => {
const modalInputs = document.querySelectorAll('.modal-input')
if (!modalInputs) return
if (!modalInputs) return // early return if dom nodes are missing
const toggleBodyScroll = (disableScroll) => {
if (disableScroll) {
document.body.style.overflow = 'hidden'
} else {
document.body.style.overflow = ''
}
}
const checkModals = () => {
let isAnyModalOpen = false
modalInputs.forEach((modalInput) => {
if (modalInput.checked) {
isAnyModalOpen = true
}
})
toggleBodyScroll(isAnyModalOpen)
}
modalInputs.forEach((modalInput) => {
modalInput.addEventListener('change', checkModals)
})
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
modalInputs.forEach((modalInput) => {
if (modalInput.checked) modalInput.checked = false
if (modalInput.checked) {
modalInput.checked = false
}
})
toggleBodyScroll(false)
}
})
checkModals()
})()
;(() => {

View file

@ -12,7 +12,7 @@
height: 100%;
width: 100%;
inset: 0;
overflow: scroll;
overflow-y: scroll;
border-radius: var(--border-radius-slight);
padding: var(--spacing-lg) var(--spacing-2xl);
@ -24,9 +24,9 @@
}
& .modal-close {
position: absolute;
top: var(--spacing-lg);
right: var(--spacing-lg);
position: sticky;
top: 0;
left: 100%;
height: var(--sizing-svg-base);
width: var(--sizing-svg-base);
}