Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions packages/coreui-react/src/components/offcanvas/COffcanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,17 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
if (_visible && !scroll) {
document.body.style.overflow = 'hidden'
document.body.style.paddingRight = '0px'
return
}

if (!scroll) {
} else if (!scroll) {
document.body.style.removeProperty('overflow')
document.body.style.removeProperty('padding-right')
}

return () => {
if (!scroll) {
document.body.style.removeProperty('overflow')
document.body.style.removeProperty('padding-right')
}
}
}, [_visible])

const handleDismiss = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,14 @@ test('COffcanvas customize and event on keypress', async () => {

vi.useRealTimers()
})

test('COffcanvas restores body scroll when unmounted while visible', () => {
const { unmount } = render(<COffcanvas visible={true} />)

expect(document.body.style.overflow).toBe('hidden')

unmount()

expect(document.body.style.overflow).toBe('')
expect(document.body.style.paddingRight).toBe('')
})
Loading