Skip to content

Commit eb0ff84

Browse files
committed
Prevent body from scrolling when modal is open
1 parent 5a1967b commit eb0ff84

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

resources/views/components/modal.blade.php

+7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@
4141
nextFocusableIndex() { return (this.focusables().indexOf(document.activeElement) + 1) % (this.focusables().length + 1) },
4242
prevFocusableIndex() { return Math.max(0, this.focusables().indexOf(document.activeElement)) -1 },
4343
}"
44+
x-init="$watch('show', value => {
45+
if (value) {
46+
document.body.classList.add('overflow-y-hidden');
47+
} else {
48+
document.body.classList.remove('overflow-y-hidden');
49+
}
50+
})"
4451
x-on:close.stop="show = false"
4552
x-on:keydown.escape.window="show = false"
4653
x-on:keydown.tab.prevent="$event.shiftKey || nextFocusable().focus()"

0 commit comments

Comments
 (0)