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

When Modal is Open Dont Allow Background to scroll #270

Merged
merged 8 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 2 additions & 0 deletions packages/react-celo/src/modals/action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import useTheme from '../hooks/use-theme';
import { Theme } from '../types';
import { useCeloInternal } from '../use-celo';
import { hexToRGB } from '../utils/colors';
import { useFixedBody } from '../utils/helpers';
import cls from '../utils/tailwind';
import { styles as modalStyles } from './connect';

Expand Down Expand Up @@ -90,6 +91,7 @@ export const ActionModal: React.FC<Props> = ({
}: Props) => {
const theme = useTheme();
const { pendingActionCount, dapp } = useCeloInternal();
useFixedBody(pendingActionCount > 0);

return (
<ReactModal
Expand Down
3 changes: 3 additions & 0 deletions packages/react-celo/src/modals/connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
} from '../types';
import { useCeloInternal } from '../use-celo';
import { hexToRGB } from '../utils/colors';
import { useFixedBody } from '../utils/helpers';
import { defaultProviderSort, SortingPredicate } from '../utils/sort';
import cls from '../utils/tailwind';

Expand Down Expand Up @@ -175,6 +176,8 @@ export const ConnectModal: React.FC<ConnectModalProps> = ({
<Placeholder />
);

useFixedBody(!!connectionCallback);

return (
<ReactModal
portalClassName={styles.portal}
Expand Down
13 changes: 13 additions & 0 deletions packages/react-celo/src/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CeloContract, CeloTokenContract } from '@celo/contractkit/lib/base';
import { useEffect } from 'react';

import { CONNECTOR_TYPES, UnauthenticatedConnector } from '../connectors';
import { localStorageKeys, WalletTypes } from '../constants';
Expand Down Expand Up @@ -92,3 +93,15 @@ export function isValidFeeCurrency(currency: Maybe<string>): boolean {
return false;
}
}

export function useFixedBody(isOpen: boolean) {
useEffect(() => {
if (isOpen) {
document.body.style.overflow = 'hidden';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to use document.body.style from feedback from @aaronmgdr

document.body.style.paddingRight = '15px';
} else {
document.body.style.overflow = 'unset';
document.body.style.paddingRight = '0px';
}
}, [isOpen]);
zhaonancy marked this conversation as resolved.
Show resolved Hide resolved
}