4
0
forked from crowetic/commerce

Remove unnecessary check in the Sidebar component (#606)

* refactor: remove unneccessary code

* refactor: remove excessive function call in modal

Co-authored-by: Gonzalo Pozzo <gonzalo.pozzo4@gmail.com>
This commit is contained in:
Lars Salling 2021-12-17 15:55:04 +01:00 committed by GitHub
parent d1f8ff007b
commit 98af5f4615
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 14 deletions

View File

@ -2,11 +2,8 @@ import { FC, useRef, useEffect, useCallback } from 'react'
import s from './Modal.module.css' import s from './Modal.module.css'
import FocusTrap from '@lib/focus-trap' import FocusTrap from '@lib/focus-trap'
import { Cross } from '@components/icons' import { Cross } from '@components/icons'
import { import { disableBodyScroll, clearAllBodyScrollLocks } from 'body-scroll-lock'
disableBodyScroll,
clearAllBodyScrollLocks,
enableBodyScroll,
} from 'body-scroll-lock'
interface ModalProps { interface ModalProps {
className?: string className?: string
children?: any children?: any
@ -34,9 +31,6 @@ const Modal: FC<ModalProps> = ({ children, onClose }) => {
window.addEventListener('keydown', handleKey) window.addEventListener('keydown', handleKey)
} }
return () => { return () => {
if (modal) {
enableBodyScroll(modal)
}
clearAllBodyScrollLocks() clearAllBodyScrollLocks()
window.removeEventListener('keydown', handleKey) window.removeEventListener('keydown', handleKey)
} }

View File

@ -1,11 +1,7 @@
import { FC, useEffect, useRef } from 'react' import { FC, useEffect, useRef } from 'react'
import s from './Sidebar.module.css' import s from './Sidebar.module.css'
import cn from 'classnames' import cn from 'classnames'
import { import { disableBodyScroll, clearAllBodyScrollLocks } from 'body-scroll-lock'
disableBodyScroll,
enableBodyScroll,
clearAllBodyScrollLocks,
} from 'body-scroll-lock'
interface SidebarProps { interface SidebarProps {
children: any children: any
@ -34,7 +30,6 @@ const Sidebar: FC<SidebarProps> = ({ children, onClose }) => {
} }
return () => { return () => {
if (contentElement) enableBodyScroll(contentElement)
clearAllBodyScrollLocks() clearAllBodyScrollLocks()
} }
}, []) }, [])