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