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:
parent
d1f8ff007b
commit
98af5f4615
@ -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)
|
||||||
}
|
}
|
||||||
|
@ -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()
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user