fix: prevent scrolling of body when model dialog is shown

This commit is contained in:
alikia2x (寒寒) 2025-05-30 03:24:37 +08:00
parent 58b4e2613c
commit 96903dec2b
Signed by: alikia2x
GPG Key ID: 56209E0CCD8420C6
2 changed files with 13 additions and 1 deletions

View File

@ -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>

View File

@ -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 && (