fix: prevent layout jump on modal open — use scrollbar-gutter: stable
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
|
||||
html {
|
||||
scroll-behavior: smooth;
|
||||
scrollbar-gutter: stable;
|
||||
}
|
||||
|
||||
body {
|
||||
|
||||
@@ -40,15 +40,9 @@ export function NewsModal({ item, onClose }: NewsModalProps) {
|
||||
}, [item, onClose]);
|
||||
|
||||
useEffect(() => {
|
||||
if (item) {
|
||||
const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
|
||||
document.body.style.overflow = "hidden";
|
||||
document.body.style.paddingRight = `${scrollbarWidth}px`;
|
||||
} else {
|
||||
document.body.style.overflow = "";
|
||||
document.body.style.paddingRight = "";
|
||||
}
|
||||
return () => { document.body.style.overflow = ""; document.body.style.paddingRight = ""; };
|
||||
if (item) document.body.style.overflow = "hidden";
|
||||
else document.body.style.overflow = "";
|
||||
return () => { document.body.style.overflow = ""; };
|
||||
}, [item]);
|
||||
|
||||
if (!item) return null;
|
||||
|
||||
@@ -74,15 +74,9 @@ export function SignupModal({
|
||||
}, [open, onClose]);
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
|
||||
document.body.style.overflow = "hidden";
|
||||
document.body.style.paddingRight = `${scrollbarWidth}px`;
|
||||
} else {
|
||||
document.body.style.overflow = "";
|
||||
document.body.style.paddingRight = "";
|
||||
}
|
||||
return () => { document.body.style.overflow = ""; document.body.style.paddingRight = ""; };
|
||||
if (open) document.body.style.overflow = "hidden";
|
||||
else document.body.style.overflow = "";
|
||||
return () => { document.body.style.overflow = ""; };
|
||||
}, [open]);
|
||||
|
||||
const handleSubmit = useCallback(async (e: React.FormEvent) => {
|
||||
|
||||
Reference in New Issue
Block a user