fix: prevent scrolling of body when model dialog is shown
This commit is contained in:
parent
58b4e2613c
commit
96903dec2b
@ -165,7 +165,7 @@ const SignUpForm: React.FC<RegistrationFormProps> = ({ backendURL }) => {
|
|||||||
>
|
>
|
||||||
Show Dialog
|
Show Dialog
|
||||||
</FilledButton>
|
</FilledButton>
|
||||||
<FilledButton type="submit" disabled={loading}>
|
<FilledButton type="submit" disabled={loading} tabIndex={1}>
|
||||||
{!loading ? <span>注册</span> : <LoadingSpinner />}
|
{!loading ? <span>注册</span> : <LoadingSpinner />}
|
||||||
</FilledButton>
|
</FilledButton>
|
||||||
<Portal>
|
<Portal>
|
||||||
|
@ -1,6 +1,17 @@
|
|||||||
import { motion, AnimatePresence } from "framer-motion";
|
import { motion, AnimatePresence } from "framer-motion";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { TextButton } from "./Buttons/TextButton";
|
import { TextButton } from "./Buttons/TextButton";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
|
export const useDisableBodyScroll = (open: boolean) => {
|
||||||
|
useEffect(() => {
|
||||||
|
if (open) {
|
||||||
|
document.body.style.overflow = "hidden";
|
||||||
|
} else {
|
||||||
|
document.body.style.overflow = "unset";
|
||||||
|
}
|
||||||
|
}, [open]);
|
||||||
|
};
|
||||||
|
|
||||||
interface DialogProps {
|
interface DialogProps {
|
||||||
show: boolean;
|
show: boolean;
|
||||||
@ -36,6 +47,7 @@ export const DialogButtonGroup: React.FC<DialogButtonGroupProps> = ({ children }
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const Dialog: React.FC<DialogProps> = ({ show, children }: DialogProps) => {
|
export const Dialog: React.FC<DialogProps> = ({ show, children }: DialogProps) => {
|
||||||
|
useDisableBodyScroll(show);
|
||||||
return (
|
return (
|
||||||
<AnimatePresence>
|
<AnimatePresence>
|
||||||
{show && (
|
{show && (
|
||||||
|
Loading…
Reference in New Issue
Block a user