feat: modal enhancements
This commit is contained in:
parent
870c40cb46
commit
54cc4bdc01
4 changed files with 36 additions and 10 deletions
4
package-lock.json
generated
4
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "coryd.dev",
|
"name": "coryd.dev",
|
||||||
"version": "24.16.5",
|
"version": "24.17.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "coryd.dev",
|
"name": "coryd.dev",
|
||||||
"version": "24.16.5",
|
"version": "24.17.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@cdransf/api-text": "^1.5.0",
|
"@cdransf/api-text": "^1.5.0",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "coryd.dev",
|
"name": "coryd.dev",
|
||||||
"version": "24.16.5",
|
"version": "24.17.0",
|
||||||
"description": "The source for my personal site. Built using 11ty (and other tools).",
|
"description": "The source for my personal site. Built using 11ty (and other tools).",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -26,19 +26,45 @@ window.addEventListener('load', () => {
|
||||||
})
|
})
|
||||||
})()
|
})()
|
||||||
|
|
||||||
// modal keyboard controls
|
// modal keyboard controls and scroll management
|
||||||
;(() => {
|
;(() => {
|
||||||
const modalInputs = document.querySelectorAll('.modal-input')
|
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) => {
|
document.addEventListener('keydown', (e) => {
|
||||||
if (e.key === 'Escape') {
|
if (e.key === 'Escape') {
|
||||||
modalInputs.forEach((modalInput) => {
|
modalInputs.forEach((modalInput) => {
|
||||||
if (modalInput.checked) modalInput.checked = false
|
if (modalInput.checked) {
|
||||||
|
modalInput.checked = false
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
toggleBodyScroll(false)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
checkModals()
|
||||||
})()
|
})()
|
||||||
|
|
||||||
;(() => {
|
;(() => {
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
inset: 0;
|
inset: 0;
|
||||||
overflow: scroll;
|
overflow-y: scroll;
|
||||||
border-radius: var(--border-radius-slight);
|
border-radius: var(--border-radius-slight);
|
||||||
padding: var(--spacing-lg) var(--spacing-2xl);
|
padding: var(--spacing-lg) var(--spacing-2xl);
|
||||||
|
|
||||||
|
@ -24,9 +24,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
& .modal-close {
|
& .modal-close {
|
||||||
position: absolute;
|
position: sticky;
|
||||||
top: var(--spacing-lg);
|
top: 0;
|
||||||
right: var(--spacing-lg);
|
left: 100%;
|
||||||
height: var(--sizing-svg-base);
|
height: var(--sizing-svg-base);
|
||||||
width: var(--sizing-svg-base);
|
width: var(--sizing-svg-base);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue