Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed main page scroll issue while popup open. #938

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 4 additions & 2 deletions packages/embeds/js/src/features/popup/components/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export const Popup = (props: PopupProps) => {
popupProps.isOpen ?? false
)

const setOverflow = value => document.body.style.setProperty('overflow', value, 'important');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setOverflow function is a good abstraction for setting the overflow property of the document.body. However, it's recommended to check if document and document.body exist before accessing their properties. This is to avoid potential errors in environments where these objects might not be available, such as server-side rendering.

- const setOverflow = value => document.body.style.setProperty('overflow', value, 'important');
+ const setOverflow = value => {
+   if (typeof document !== 'undefined' && document.body) {
+     document.body.style.setProperty('overflow', value, 'important');
+   }
+ };


onMount(() => {
const paymentInProgress = getPaymentInProgressInStorage()
if (popupProps.defaultOpen || paymentInProgress) openBot()
Expand Down Expand Up @@ -90,14 +92,14 @@ export const Popup = (props: PopupProps) => {
const openBot = () => {
setIsBotOpened(true)
popupProps.onOpen?.()
document.body.style.overflow = 'hidden'
setOverflow('hidden');
document.addEventListener('pointerdown', closeBot)
}

const closeBot = () => {
setIsBotOpened(false)
popupProps.onClose?.()
document.body.style.overflow = 'auto'
setOverflow('auto');
document.removeEventListener('pointerdown', closeBot)
}

Expand Down