Skip to content

Commit 1f5543e

Browse files
committed
refactor(CModal): prevent body scroll when the modal is visible
1 parent 7eeeb5e commit 1f5543e

File tree

1 file changed

+4
-0
lines changed
  • packages/coreui-vue/src/components/modal

1 file changed

+4
-0
lines changed

packages/coreui-vue/src/components/modal/CModal.ts

+4
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ const CModal = defineComponent({
145145
const handleEnter = (el: RendererElement, done: () => void) => {
146146
executeAfterTransition(() => done(), el as HTMLElement)
147147
document.body.classList.add('modal-open')
148+
document.body.style.overflow = 'hidden'
149+
document.body.style.paddingRight = '0px'
148150
el.style.display = 'block'
149151
setTimeout(() => {
150152
el.classList.add('show')
@@ -160,6 +162,8 @@ const CModal = defineComponent({
160162
const handleLeave = (el: RendererElement, done: () => void) => {
161163
executeAfterTransition(() => done(), el as HTMLElement)
162164
document.body.classList.remove('modal-open')
165+
document.body.style.removeProperty('overflow')
166+
document.body.style.removeProperty('padding-right')
163167
if (document.body.className === '') {
164168
document.body.removeAttribute('class')
165169
}

0 commit comments

Comments
 (0)